okay so we're gonna look at a little algorithm to extract an initial so a
letter from a list of items from a larger 2d array or list that is in the
CSV okay so I'm just here I've got a CSV of numbers second names first names the
film they're gonna see and the day they're gonna see it okay so this is my
CSV Oh information so this bit of code here no I'm just just to explain I'll
put this in a procedure just up here so you don't necessarily have to have this
but I've just done it that way so just this block of code here what this will
do this will get the data from the CSV and it will append all the data to a new
list called data okay we can check this by doing
print data and this should give us all of that CSV okay there is been sort of
squished up that's the entire csru so we know the CSV is now in our program so as
it's there we can now start to do things with it so the first bit of code down
here okay I've kind of explained it in the comment but basically I've got a new
variable which are called DB length so database length and this gives us the
length of the list okay so in other words how many items are in the list
okay now we need this because what we're gonna be doing is we're gonna be picking
a random item from the list okay and so to do this we're gonna generate a random
number between 0 and the length of the list okay so if there's 15 people in the
list it will generate a number between 0 and 15 ok now I've put minus 1 on there
because in a minute we're gonna be using index numbers and if there's 15 people
in the list the last person the 15th person the index number of their
position in the list will be 14 so if we leave if we don't have minus 1 it could
generate 15 which would mean our list with
out of range okay so so far we've got a random number generated which I have
assigned the variable random name or Rand underscore name so again we can
check this works okay just by doing a printer and name it should give me a
random number okay there we go four just ignore the end for the moment
okay good so okay so next what we're gonna do here is we're gonna get the
randomly selected name from our list okay so if you remember here's our CSV
it's going to look in this column and it's gonna get a random name from this
column okay now we can accomplish that by doing I've made a variable called
chosen name and I've made it I've assigned to it data which is our list if
you remember so data is all of this okay and I said Rand named know if you
remember that was the random number we generated and then the next set of
brackets means the column within our our list okay so in other words column index
position number two so to explain how this works I'll go back to the CSV this
is column zero this is column 1 this is column two so this is the reason I've
got two indexes when I look in column two and it's gonna pick a random one
from these using the random number we have just generated okay and it's gonna
assign that name to the variable chosen the name now just to explain or show
that working you're just gonna go run this program it should give us one of
the names there we go Dave and I'm just gonna keep running it so you can see
there each time it's picking a random name from column number two okay zero
one two okay so random name from each of these
okay so if we then want to pick a random assault and if we then want the initial
from the name okay because sometimes we write a letter we say like dear mr. d
dangerous or whatever the name is is the are the initial so it's useful to get an
initial from a first name so we can put the index number of the first letter in
the nail and we do that by rather than printing the whole name
we go chosen name and then in brackets 0 okay and 0 is the first initial for that
string so if I go back here it will look at J DJ envy and so on okay so if we now
run this what we will get is a load of initials okay so all these initials have
been picked randomly from our list of names from our CSV so that's how we pick
an initial at random from a list of people they're in a CSV