Random Function
The random function returns a random number.
random(int max)
Returns a random number.
Input
You need to give it an int
called max
as an input. This int
is the biggest number you random is allowed to return to you as a result.
Returns
It returns an int between 0
and the the max
input.
Example
// creates a variable called number
// sets the number variable to a random value between 0-100
int number = random(100);
// prints the number to Serial
Serial.println(number);
Tips
This function is useful when you want to have unpredictable results. For example you could use random(6)
to simulate rolling a die.