On 2017-01-27 17:13, Leigh wrote:
On 27 January 2017 at 14:30, Lauri Kenttä <lauri.ken...@gmail.com> wrote:
This needs to be thought of as 2^32 possible _streams_ with a period
of (2^19937)−1. Offset within the stream is as important as the stream
variation itself.

This is not true. There is one stream of period (2^19937)−1, and
the initial state defines the current position in that stream.

I'm not sure about this, the LCG constant used in the initial
generator seems completely unrelated to the rest of the algorithm, so
I don't see how this offsets the stream position.

If it is truly the case, I stand corrected.

I'm sorry, I oversimplified a bit in a hurry.
MT has (2^19937)−1 possible internal states, and I understand that
it's supposed to go through all these, hence the (2^19937)−1 period.
In each state, mt_rand returns 624 values of 32 bits before
"twisting" to the next state. Initializing with a different state
offsets the stream position just as it would in a LCG, but because
of the huge state and with the current MT initialization method,
it's very difficult to say what that offset actually would be.
But still, starting with mt_srand(0) and looping trough mt_rand,
you should eventually end up in the same state as mt_srand(1).
It might take around 2^(19937-32) * 624 mt_rand calls, though.

--
Lauri Kenttä

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to