Random Number

This library allows users to get a random number.

randomSeed

Description
randomSeed() initializes the pseudo-random number generator, causing it to start at an arbitrary point in its random sequence. This sequence, while very long, and random, is always the same.
Syntax
randomSeed(unsigned int seed)
Parameters
seed: A number to generate the seed
Returns
None

random

Description
The random function generates pseudo-random numbers.
Syntax
long random(long min_num, long max_num)
Parameters
min_num: Lower bound of the random value, inclusive (optional)
max_num: Upper bound of the random value, exclusive
Returns
A random number between min and max-1 (long)

Example

This example outputs a random number from 0 to 99 every 100ms.


#include <Arduino.h>

#define INTERVAL 100
 
void setup()
{
    Serial.begin(9600);
    randomSeed(millis());
}
 
void loop()
{
    Serial.println( random(0, 100) );
    delay(INTERVAL);
}