random () function in p5 (which you can read about here) is similar to the more common
Math.random () function, (which you can read about here), but with some extra features built in.
Just by itself, p5’s
random () behaves exactly like
Math.random () – it returns a value between
1. It might very, very occasionally return a value of exactly
0, but it will never return a value of exactly
1, only values very close to it.
One numerical argument
random () a single numerical value specifies a maximum. In this case, the function returns a random value between
0 and that maximum. For example,
random (2) will return a decimal value between
Two numerical arguments
random () two numerical values specifies a minimum, and a maximum. For example
random (2, 8) will return a random decimal value between
If you give p5’s
random () function an array, it will select one of the elements of that array at random, and return it.