class Mersenne_Twister

This provides a deterministic pseudo-random sequence that is seedable

Since PHP 5.2.1 mt_srand() and mt_rand() don't generate predictable sequences since PHP 5.2.1. The following code:

$code = 12345; $MT = new \Tsugi\Util\Mersenne_Twister($code); for($i=0; $i < 30; $i++ ) { $ran = $MT->getNext(0,6); echo $ran." "; }

Will always print out:

2 3 3 6 5 1 5 3 4 2 1 6 5 4 0 6 0 2 0 3 5 6 6 3 1 3 2 6 3 3

Note that this is written for a 64-bit system and will generate different sequences on 32 and 64 bit systems.

Constants

MAX

Methods

__construct($seed = null)

No description

setSeed($seed)

No description

getNext($min = null, $max = null)

Get the next pseudo-random number in the sequence

gaussian($max, $lambda = 0.2)

No description

shuffle($arr)

No description

Details

at line 33
__construct($seed = null)

Parameters

$seed

at line 40
setSeed($seed)

Parameters

$seed

at line 71
getNext($min = null, $max = null)

Get the next pseudo-random number in the sequence

Returns the next pseudo-random number in the range specified. The $max and $min are inclusive. If $max and $min are omitted a large integer is returned.

Parameters

$min The low end of the range (optional)
$max The high end of the range (optional)

at line 107
gaussian($max, $lambda = 0.2)

Parameters

$max
$lambda

at line 121
shuffle($arr)

Parameters

$arr