Capítulo 141 de 411

Chapter 141: gsap.utils.random()

Core Idea

random() returns a random number within a range (optionally snapped to an increment), or randomly picks an element from an array.

Reference Tables

SignatureDescription
random(min, max, snapIncrement?, returnFunction?)random number, optionally snapped; pass returnFunction: true for a reusable randomizer
random(array)randomly picks one element from the array

Code Examples

gsap.utils.random(-100, 100); // random number, no snapping
gsap.utils.random(0, 500, 5); // snapped to nearest multiple of 5
gsap.utils.random(["red", "green", "blue"]); // random array element