random

This module provides random number generation functions.

The current random number generator is implemented as a Mersenne Twister PRNG which is automatically seeded on startup with data from os.urandom().

This module should be preferred to using Math.random since it uses a more roubust implementation. The implementation used my Math.random can be found here.

Note

This module could use some peer review. If you are competent to do so, please get in touch.

Random objects

class random.Random([seed])

Class implementing the Mersenne Twister PRNG. While users are free to create multiple instances of this class, the module exports the seed and random functions bound to a default instance which is seeded with the default seed.

random.Random.prototype.seed([seed])

Seed the PRNG. seed can be a number or an Array of numbers. If null or undefined is passed a default seed is obtained from os.urandom(). The default seed consists of 2496 bytes, enough to fill the Mersenne Twister state.

random.Random.prototype.random()

Return a random floating point number in the [0.0, 1.0) interval.

SystemRandom objects

class random.SystemRandom()

Class implementing a similar interface to random.Random(), but using os.urandom() as the source for random numbers.

random.SystemRandom.prototype.random()

Return a random floating point number in the [0.0, 1.0) interval.

Functions

random.random()

Return a random floating point number in the [0.0, 1.0) interval. The default random.Random() instance is used.

random.seed([seed])

Seed the default random.Random() instance.