[−][src]Static p5_sys::global::random
pub static random: RandomInternalType
Return a random floating-point number.
Takes either 0, 1 or 2 arguments.
If no argument is given, returns a random number from 0 up to (but not including) 1.
If one argument is given and it is a number, returns a random number from 0 up to (but not including) the number.
If one argument is given and it is an array, returns a random element from that array.
If two arguments are given, returns a random number from the first argument up to (but not including) the second argument.
Examples
for (let i = 0; i < 100; i++) { let r = random(50); stroke(r * 5); line(50, i, 50 + r, i); }
for (let i = 0; i < 100; i++) { let r = random(-50, 50); line(50, i, 50 + r, i); }
// Get a random element from an array using the random(Array) syntax let words = ['apple', 'bear', 'cat', 'dog']; let word = random(words); // select random word text(word, 10, 50); // draw the word
Overloads
min?
the lower bound (inclusive)
max?
the upper bound (exclusive)
choices
the array to choose from