Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97991 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81727 invoked from network); 27 Jan 2017 16:08:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jan 2017 16:08:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=lauri.kentta@gmail.com; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=lauri.kentta@gmail.com; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain gmail.com does not designate 178.62.210.197 as permitted sender) X-PHP-List-Original-Sender: lauri.kentta@gmail.com X-Host-Fingerprint: 178.62.210.197 k-piste.dy.fi Received: from [178.62.210.197] ([178.62.210.197:36172] helo=k-piste.dy.fi) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2B/59-28703-5807B885 for ; Fri, 27 Jan 2017 11:08:38 -0500 Received: from localhost.localdomain ([::1] helo=k-piste.dy.fi) by k-piste.dy.fi with esmtp (Exim 4.88) (envelope-from ) id 1cX92f-0001Ds-VH; Fri, 27 Jan 2017 18:06:25 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Fri, 27 Jan 2017 18:06:25 +0200 To: Leigh Cc: Yasuo Ohgaki , Niklas Keller , Nikita Popov , internals@lists.php.net In-Reply-To: References: <71c26cd6df6f59e76dafd31647852c2e@koti.fimnet.fi> <142a3537a99809cf23d78e0eaadc3aef@gmail.com> <7a359bb08b0ad8b046534c15492cec91@gmail.com> <8cfe7a3ea5a05fc3e5347e9af848ada0@gmail.com> <1913d779b7954d5c099ed66821cb299c@gmail.com> Message-ID: <22fd75b88e253b0eb58cc789fd800760@gmail.com> X-Sender: lauri.kentta@gmail.com User-Agent: Roundcube Webmail/1.2.3 Subject: Re: [PHP-DEV] Re: Improving mt_rand() seed From: lauri.kentta@gmail.com (=?UTF-8?Q?Lauri_Kentt=C3=A4?=) On 2017-01-27 17:13, Leigh wrote: > On 27 January 2017 at 14:30, Lauri Kenttä > 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ä