Returns a random number within a range, random item from an array, or returns a function to return those things depending on what you give it.
Gets a random number within a range (optionally rounding to an increment you provide), or choose a random item in an array. Note that if you add
true as the 4th parameter, it tells
gsap.utils.random() to return a
function that you can call anytime to get a random value according to all the parameters you defined.
//get a random number between -100 and 100
var num = gsap.utils.random(-100, 100);
//get a random value from an array (in this case we'll get "red", "blue", or "green")
var random = gsap.utils.random(["red", "blue", "green"]);
//get a random number between -100 and 100 that's snapped to the closest increment of 5
var num = gsap.utils.random(-100, 100, 5);
//use the 4th parameter (boolean) to get a function back instead of a number
var randomizer = gsap.utils.random(-100, 100, 5, true);
//now we just call that randomizer function from the line above and it'll always return a number between -100 and 100 rounded to the closest increment of 5!
var num = randomizer();