The comfortable framework for making games in Wren
The random module provides utilities for generating pseudo-random numbers, for a variety of applications. Please note, this module should not be used for applications which require a cryptographically secure source of random numbers.
DOME’s provides two pseudo-random number generators - the “Squirrel3” noise function, described by Squirrel Eiserloh in this talk, and “Squirrel5” noise function, which is an improvement over the “Squirrel3” generator.
The Squirrel3 class, also exposed as Random, and the Squirrel5 class both provide the same
API, as documented below.
noise(x: Number): NumberGiven x as an integer, this will return a 32-bit number based on the Squirrel3 noise function.
noise(x: Number, seed: Number): NumberGiven x and seed as integers, this will return a 32-bit number based on the Squirrel3 noise function. The seed value can be used to get different outputs for the same position x.
construct new()Creates a new instance of a random number generator, seeded based on the current system time.
construct new(seed: Number)Creates a new instance of a random number generator, based on the provided seed value.
float(): NumberReturns a floating point value in the range of 0.0...1.0, inclusive of 0.0 but exclusive of 1.0.
float(end: Number): NumberReturns a floating point value in the range of 0.0...end, inclusive of 0.0 but exclusive of end.
float(start: Number, end: Number): NumberReturns a floating point value in the range of start...end, inclusive of start but exclusive of end.
int(end: Number): NumberReturns an integer in the range 0.0...end, inclusive of 0.0 but exclusive of end.
int(start: Number, end: Number): NumberReturns an integer in the range start...end, inclusive of start but exclusive of end.
sample(list: List): AnyGiven a list, this will pick an element from that list at random.
sample(list: List, count: Number): ListRandomly selects count elements from the list and returns them in a new list. This provides “sampling without replacement”, so each element is distinct.
shuffle(list: List): ListUses the Fisher-Yates algorithm to shuffle the provided list in place. The list is also returned for convenience.