Random Numbers Documentation
Random Methods
b8.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.
b8.Random.coord2D(x, y, seed)
Returns a consistent pseudo-random number between 0 and 1 for the given 2D coordinates and seed. Uses a simple hash function to generate the number.
Parameters
- x (number): The x coordinate.
- y (number): The y coordinate.
- seed (number): The seed value.
Returns
- (number): A pseudo-random number between 0 and 1.
b8.Random.getSeed()
Returns the seed for the random number generator.
Returns
- (number): The seed for the random number generator.
b8.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.
b8.Random.num()
Returns a random number between 0 and 1.
Returns
- (number): A random number between 0 and 1.
b8.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.
b8.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.
b8.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.
b8.Random.reset()
Resets the random number generator to its initial state. This clears the seed and any cached weighted arrays.
Returns
- (void):
b8.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.
Returns
- (void):
b8.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.
b8.Random.smooth2D(x, y, seed, freq)
Returns a smooth noise value between 0 and 1 for the given 2D coordinates and seed. Uses bilinear interpolation between the corner values.
Parameters
- x (number): The x coordinate.
- y (number): The y coordinate.
- seed (number): The seed value.
- freq (number): The frequency of the noise.
Returns
- (number): A smooth noise value between 0 and 1.
b8.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.