Re: mt_srand with array seed?

From: Date: Sun, 14 Aug 2016 14:04:22 +0000
Subject: Re: mt_srand with array seed?
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-95139@lists.php.net to get a copy of this message
On 8/14/16, 5:45 AM, "Lauri Kenttä" <lauri.kentta@gmail.com> wrote: >On 2016-08-13 18:53, Tom Worster wrote: >> On 8/12/16 2:48 PM, Lauri Kenttä wrote: >>> On 2016-08-12 21:40, Tom Worster wrote: >>>> mt_srand() will work. But what would be in the array? Integers from >>>> which the upper 32 bits, if they exist, are discarded? >>> >>> mt19937ar.c contains init_by_array. >>> Compability with that would probably be a good goal, >>> unless someone can point out another widely used implementation. >> >> Would mt_srand([1,2,3,4,5,6,7,8]) set the same seed on 32 and 64 bit >> machines? > >Of course it would. >Or let's phrase it this way: can you think of any reason why it >shouldn't? An array of N PHP (signed) integers in a 64bit PHP runtime can provide 2N unsigned long seed values to MT. If mt_srand() did that then I don't see how portability is maintained. Otoh, if, for the sake of portability, which I imagine most would prefer, mt_srand() discards bits from 64bit input integers then mt_rand() will produce the same sequence for many different mt_srand() seeds. This would be new and at odds with conventions of how seeds affect PRNG outputs. Hence I asked on Friday about discarding bits from the array on 64bit PHP. You pointed me to mt19937ar.c, in which I did not find the answer. My skill in C is inadequate. It is still not clear to me how the improved mt_srand() would work. Tom

« previous php.internals (#95139) next »