How to call on random value in your array?

This post was flagged by the community and is temporarily hidden.

You can pass an array into the random() function. From the p5.js reference:

// 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

Or you could also convert your random decimal number to an integer. Try googling “JavaScript convert decimal to integer” for a bunch of results.

(btw, you might consider using less colorful examples in the forum, as maybe not everybody wants to read that kind of thing)

1 Like