Re: Re: Improving mt_rand() seed
| From: | Lauri Kenttä | Date: | Fri, 27 Jan 2017 16:06:25 +0000 |
| Subject: | Re: Re: Improving mt_rand() seed | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-97991@lists.php.net to get a copy of this message | ||
On 2017-01-27 17:13, Leigh wrote:
On 27 January 2017 at 14:30, Lauri Kenttä <lauri.kentta@gmail.com> wrote: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ä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.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.