sup.random
The sup.random package provides methods for generating random numbers and working with randomized arrays.
Methods
sup.random.integer()
(min: number, max: number) → number
// Random number between 1 and 6 (inclusive)const roll = sup.random.integer(1, 6);Returns a random integer between min and max (inclusive).
sup.random.float()
(min: number, max: number) → number
// Random probability between 0 and 1const probability = sup.random.float(0, 1);Returns a random floating point number between min and max (inclusive).
sup.random.boolean()
() → boolean
// Random true/false with 50% probabilityconst coinFlip = sup.random.boolean();Returns true or false with equal probability (50/50).
sup.random.choice()
<T>(arr: T[]) → T
// Pick a random colorconst color = sup.random.choice(["red", "green", "blue"]);
// Pick a random patch assetconst randomAsset = sup.random.choice(sup.assets);Returns a random element from the given array.
sup.random.shuffle()
<T>(arr: T[]) → T[]
// Shuffle an array of numbersconst numbers = sup.random.shuffle([1, 2, 3, 4, 5]);
// Create a randomized order of usersconst queue = sup.random.shuffle([...users]);Shuffles the array using the Fisher-Yates algorithm and returns the shuffled array.