Random Numbers Documentation
Random Methods
beep8.Random.chance(probability)
Returns a random boolean value based upon the probability percentage provided.
Parameters
- probability (number): A percentage value between 0 and 100 representing the chance of returning true.
Returns
- (boolean): True with the specified probability, false otherwise.
beep8.Random.getSeed()
Returns the seed for the random number generator.
Returns
- (number): The seed for the random number generator.
beep8.Random.int(min, max)
Returns a random integer in the given closed interval.
Parameters
- min (number): The minimum value (inclusive).
- max (number): The maximum value (inclusive).
Returns
- (number): A random integer between min and max.
beep8.Random.num()
Returns a random number between 0 and 1.
Returns
- (number): A random number between 0 and 1.
beep8.Random.pick(array)
Returns a randomly picked element of the given array.
Parameters
- array (Array): The array to pick from.
Returns
- (any): A randomly picked element of the array, or null if the array is empty.
beep8.Random.pickWeighted(array, decayFactor)
Returns a randomly picked element of the given array, with a weighted probability.
Parameters
- array (Array): The array to pick from, with each element repeated a number of times.
- decayFactor (number): The decay factor for the weighted array.
Returns
- (any): A randomly picked element of the array, or null if the array is empty.
beep8.Random.range(min, max)
Returns a random number (float) in the given closed interval.
Parameters
- min (number): The minimum value (inclusive).
- max (number): The maximum value (inclusive).
Returns
- (number): A random number between min and max.
beep8.Random.setSeed(seed)
Sets the seed for the random number generator. If the seed is null, the random number generator will reset to use the current time.
Parameters
- seed (number|string): The seed to use for the random number generator.
beep8.Random.shuffleArray(array)
Shuffles an array, randomly reordering the elements. Does not modify the original array. Returns the shuffled array.
Parameters
- array (Array): The array to shuffle.
Returns
- (Array): The shuffled array.
beep8.Random.weightedArray(array, decayFactor)
Returns a weighted array of elements. The array uses a decay factor to determine the number of times each element should be repeated.
Parameters
- array (Array): The array to weight.
- decayFactor (number): The decay factor for the weighted array.
Returns
- (Array): The weighted array.