today i want to teach you how to generate random numbers and also how to pick a
random item from a list so that one is not exactly going to be a random number
but it's kind of related if you want to support this channel
please leave a like and comment just being more active goes a long way so in order to
generate a random number in google sheets there are three functions one of them is called rand
like this and what this is going to do it's going to generate a random number between 0 and 1 and 1
not included so basically between 0 and 0.99999 and then there is another function that one is
randbetween this is more for generating a whole number and for this one you give it a low and high
and it's going to generate a number between those numbers so for example if i do 1 and 10
this is going to generate a random number between 1 and 10. as you change something in a spreadsheet
those random numbers are gonna update and it's going to generate a new number so you
can obviously change this to any number you want as the low and high so if you wanted
to generate let's say a random five digit number then you would start something like 10 000 up to
99 000. so basically the first number in that five digit number less than the last number and
that should give us a random five digit number and then finally the third function here is rand array
and this generates a random array this is very similar to this function this first rand function
the only difference is instead of generating just one it's going to generate an array of numbers so
here you have rows and columns so if i type 2 for example for rows and columns are optional here so
if i close parentheses and hit enter c generates two rows of random numbers i can go here and do a
comma and do four columns so two rows four columns and that's going to generate an array of random
numbers basically an array of this in this whole area so if you wanted an array you could use this
red array instead of just regular rand function so if you're trying to get a whole number
this rant between is your friend if you're trying to get a number that has certain decimal points
you could actually combine this with this so i could just take this that generates a random
number and then i could add that rand function to generate something with decimal points
and if you wanted this to be a certain number of decimal points here instead of
any number of decimal points you could just go here and add round to this and then provide
decimal places so if i do two decimal places that's going to be two decimal place right
here after this if you want it four decimal places you can round to four that is actually doing four
this is just now not formatted correctly so let's actually add a few that small points
so there you go as you change your data that should update as usual now the next thing i
want to go over is this random array example so this random array gives you this decimal
point number in a ray format but what if you wanted to have a whole number in this array
now there is no rand array like that rand between to basically give you an array of integers so what
you can do is that you can just take this which gives you a number between 0 and 1 multiplied by
a number so for example if i do 10 and here to make sure this works i'm going to do command
shift enter or ctrl shift enter to do array formula i'm going to hit enter and you're
going to see that what's going to happen here we generate basically a number between 0 and 9.99
right this basically we just move the decimal point by multiplying that whole thing by 10.
what i can do now i can take this number if i didn't want this decimal points and all of that
i can just take that and do something like int to remove decimal points to use int function integer
so what this is going to do it's basically just going to now give us a number between 0
and 9 because what's going to happen is see we get a 0 but we're never going to reach 10 because
even if it's 9.9999 it's going to trim the rest and we're gonna get to nine now if your intention
was to generate a random number between let's say one to ten this gives me zero to nine so
i can just go here do plus one and this should now generate a number between 1 to 10. and if i
wanted to get a number let's say between 1 and 100 i would just multiply this by 100 or really
any number like you could do 50. so now it would be a number between 1 and 50. and then finally
let's go over a case of selecting something from a list so let's say we have a random list
and we'd like to pick one of these names in a list randomly so the way we can do that is by
creating a randbetween function and i'm gonna just provide one as a starting point comma and then
however many items i have here so in this case i have one two three four five right so i'm gonna
do five so this is gonna give me a random number between one and five now if i wanted this to just
select a name from this instead of just giving me one to five i can just put this inside of index
function and in index function i'm gonna highlight this range of names comma and then we can just as
an index provide that random position between one and five and if i hit enter see that gives me kate
so that should be your random item from a list so if you wanted to do something like that
you can and if you didn't want this to be a range from a spreadsheet
you could also just hard code this in an array like this and uh joe and basically just comma
separate this list i'm just gonna do three this time and just change this between one and three
and that would be a random item from this list of three now i don't have to have this over here
and that should do it thanks for watching and i'll see in the next video