top of page

11 Math Functions

random()

The random function generates pseudo-random numbers.



Notes and Warnings

If it is important for a sequence of values generated by random() to differ, on subsequent executions of a sketch, use randomSeed() to initialize the random number generator with a fairly random input, such as analogRead() on an unconnected pin.

Conversely, it can occasionally be useful to use pseudo-random sequences that repeat exactly. This can be accomplished by calling randomSeed() with a fixed number, before starting the random sequence.

random(max)

random(min, max)


min: lower bound of the random value, inclusive (optional).

max: upper bound of the random value, exclusive.


Returns

A random number between min and max-1. Data type: long.




© 2021 Odyssey Navigator. All rights reserved.

bottom of page