arduinoRandom Numbers


Syntax

  • random(max) //Returns a (long) pseudo-random number between 0 (inclusive) and max (exclusive)

  • random(min, max) //Returns a (long) pseudo-random number between min (inclusive) and max (exclusive)

  • randomSeed(seed) //Initializes de pseudo-random number generator, causing it to start at a specified point in its sequence.

Parameters

ParameterDetails
minThe minimum possible value (inclusive) to be generated by the random() function.
maxThe maximum possible value (exclusive) to be generated by the random() function.
seedThe seed that will be used to shuffle the random() function.

Remarks

If randomSeed() is called with a fixed value (eg. randomSeed(5)), the sequence of random numbers generated by the sketch will repeat each time it is run. In most cases, a random seed is preferred, which can be obtained by reading an unconnected analog pin.