Class Index | File Index

Classes


Class SeedableRandom

A fast, deterministic, seedable random number generator.
Defined in: random.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Unlike the native random number generator built into most browsers, this one is deterministic, and so it will produce the same sequence of outputs each time it is given the same seed.
Field Summary
Field Attributes Field Name and Description
 
The last value the random number generator was seeded with.
 
Alias for next();
Method Summary
Method Attributes Method Name and Description
 
next()
Get the next random number between 0 and 1 in the current sequence.
 
nextInt(a, gs)
Get the next random integer in the current sequence.
 
seed(x)
Seed the random number generator.
 
seed2d(x, y)
Seed the random number generator with a two dimensional seed.
 
seed3d(x, y, z)
Seed the random number generator with a three dimensional seed.
Class Detail
SeedableRandom(seed)
Unlike the native random number generator built into most browsers, this one is deterministic, and so it will produce the same sequence of outputs each time it is given the same seed. By default it is seeded with the current time, which means the output is effectively non-deterministic. To make the output deterministic (e.g. the same each time) you should seed it with your own number. This code is based on George Marsaglia's MWC algorithm from the v8 Javascript engine.
Parameters:
seed
is an optional number to set the initial seed.
Field Detail
last_seed
The last value the random number generator was seeded with.

random
Alias for next();
Method Detail
next()
Get the next random number between 0 and 1 in the current sequence.

nextInt(a, gs)
Get the next random integer in the current sequence.
Parameters:
a
The lower bound of integers (inclusive).
gs
The upper bound of integers (exclusive).

seed(x)
Seed the random number generator. The same seed will always yield the same sequence. Seed with the current time if you want it to vary each time.
Parameters:
x
The seed.

seed2d(x, y)
Seed the random number generator with a two dimensional seed.
Parameters:
x
First seed.
y
Second seed.

seed3d(x, y, z)
Seed the random number generator with a three dimensional seed.
Parameters:
x
First seed.
y
Second seed.
z
Third seed.

Documentation generated by JsDoc Toolkit 2.4.0 on Fri Nov 09 2012 21:19:32 GMT+0800 (WST)