RANDOM NUMBER FUNCTIONS
If you need to generate random numbers, you can use Arduino's pseudorandom number generator.
randomSeed(seed)
Resets Arduino's pseudorandom number generator. Although the distribution of the numbers returned by random() is essentially random, the sequence is predictable. So, you should reset the generator to some random value. If you have an unconnected analog pin, it will pick up random noise from the surrounding environment (radio waves, cosmic rays, electromagnetic interference from cell phones and fluorescent lights, and so on).
Example:
randomSeed(analogRead(5)); // randomize using noise from pin 5
long random(max) long random(min, max)
Returns a pseudorandom long integer value between min and max – 1. If min is not specified, the lower bound is 0.
Example:
long randnum = random(0, 100); // a number between 0 and 99 long randnum = random(11); // a number between 0 and 10
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access