Random
Add chaos to your program by learning about randomization

How to Program Random

With programming we usually want things to happen the same every time through the loop, but there are cases when we want things to be randomized.

To create a random value we have two different ways to do it.

`int value = random(max);`

or

`int value = random(min, max);`

Note that min and max are to be replaced with actual numbers in your code. The first will return a value from 0 up to (but not including) max. Then the second one will return a value between min and max. Both of these can pick the lowest number (0 or min), but it will never pick the max  value. We can then use these values to make random decisions. For example:

```int choice;

void setup() {
Serial.begin(9600); // start the Serial monitor
}

void loop() {
choice = random(4); // pick a random number from 0-4 (not including 4)

// print out a message depending on the random number
if(choice == 0)
{
Serial.println("Hi");
}
else if (choice == 1)
{
Serial.println("Bye");
}
else if (choice == 2)
{
Serial.println("Good morning");
}
else if (choice == 3)
{
Serial.println("Good night");
}

delay(500); // slow it down to watch what is happening
}```

This one will randomly pick a number between 0 and 4. Then using if statements (if you want to learn more checkout this tutorial) it will print a different message depending on the random choice. It will then wait half a second and repeat this process.

Here is some example output:
Good night
Bye
Bye
Good morning
Good morning
Hi
Hi
Good morning
Good night
Bye
Hi
Bye
Hi
Good morning
Good night