|
-
Senior Member
PRNG question / idea
Can any math-inclined people tell me if this works...?
I'm looking for a better way to seed mt_rand(), something that would yield more than the million seeds you get from (double)microtime()*1000003.
Some people have suggested something like:
PHP Code:
$seed=hexdec(substr(md5((double)microtime()*1000003),-8)) & 0x7fffffff;
But I don't see how this is any more random, since there are only a million md5 hashes you can generate from microtime anyway; the pool is the same size.
In my application, a secondary (though less-reliable) source of randomness is that I don't know the exact last time the generator was seeded, because it hinges sometimes on user interaction. (Other times, reseeding happens in a loop). So my thought was that I could try this:
PHP Code:
$seed=hexdec(substr(md5((double)microtime()*1000003),-mt_rand(6,8))) & 0x7fffffff;
which I think should leverage the (unknowable) last seed to choose the length of the md5 substring, which could now yield 6, 7 or 8 digit long hexidecimals (instead of 8 digits only).
My question is, does this increase the true number of possible random seeds to 3 million? Or is that an error in my reasoning?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|