random

Random selection and number generation
random
Random( seed ) constructor
Random.prototype.number()
Random.prototype.pick( m, n )
Random.prototype.pickOtherThan( m, n, excluded )
Random.prototype.d6()
Random.prototype.rollDice( [n], [showDice] )
Array.prototype.pick()
Array.prototype.pickOtherThan( excluded )
Array.prototype.shuffle()

Random selection and number generation

random

A shared global instance of Random.

Random( seed ) constructor

A constructor to create a new Random object. If a seed is given, the random number generator will use it as an initial seed value. This makes the number sequence it generates reproducable for testing purposes.

seed optional seed value

Random.prototype.number()

Returns a random number between 0 (inclusive) and 1 (exclusive). Effectively the same as Math.random(), but uses the random number generator of this Random object.

Random.prototype.pick( m, n )

Returns a random integer between m (inclusive) and n (inclusive).

m one end of the range
n the other end of the range

Random.prototype.pickOtherThan( m, n, excluded )

Returns a random integer between m (inclusive) and n (inclusive), but excluding the value of excluded.

m one end of the range
n the other end of the range
excluded a value that will never be returned

Random.prototype.d6()

Returns the result of rolling a simulated 6-sided die. A convenience for Random.pick( 1, 6 ).

Random.prototype.rollDice( [n], [showDice] )

Simulates rolling n dice. If showDice is true, an image of each die result is printed to the console. The values rolled are returned in an array.

n the optional number of dice to roll (default is 1, must be non-negative)
showDice if true, the results are printed to the console graphically (default is true)

returns an array containing the n numbers that were rolled

Array.prototype.pick()

Randomly returns one element of the array. The random selection is made using random. An extension to all Array objects.

Array.prototype.pickOtherThan( excluded )

Randomly returns one element of the array other than any element equal to excluded. An extension to all Array objects.

excluded a value that will never be returned

Array.prototype.shuffle()

Shuffles the contents of an array into random order. An extension to all Array objects.

Contents