Module gamejs/math/random

A seedable random-number generator.

A generator is initialized by GameJs and can be used with the static functions of this module:

gamejs.random.choose([1,2,4]); // integet between and including 2 and 5 gamejs.random.integer(2, 5);

You can re-initialize this generator with a different seed by calling gamejs.utils.prng.init(seed) after which the static functions in this module will use the new seed.

Functions

Class Alea

Instance Methods


Alea (seed)

A seedable pseudo-random number generator.

Parameters

Number|String seed the seed for generating the numbers

Alea.prototype.choose (items)

Parameters

items

Alea.prototype.integer (min, max)

Parameters

min
max

Alea.prototype.random ()

Returns

Number the next random number as determined by the seed

Alea.prototype.vector (min, max)

Parameters

min
max

choose (items)

Parameters

Array items

Returns

Object random item from items list

init (seed)

Re-initialize the per instance random number generator used in the static functions on this module (e.g. vector())

Parameters

Number|String seed

integer (min, max)

Parameters

Number min
Number max

Returns

Number random integer between min and max

random ()

Returns

Number next random float between 0 and 1

vector (minVector, maxVector)

Parameters

Array minVector 2 integers, the minimum vector
Array maxVector 2 integers, the maximum vector

Returns

Array a random vector [min[0]<=x<=max[0], min[1]<=y<=max[1]]