On Tue, Mar 10, 2009 at 11:54 AM, Dan Cech <dc...@phpwerx.net> wrote:
> Chris Snyder wrote:
>> Add a random number to a sufficiently deep timestamp (microseconds)
>> and you will have a non-repeating random number. But you can't shorten
>> it to 8 characters or whatever -- you have to keep the full timestamp
>> in order to maintain non-repeatability.
>
> Not really, if you add a random number then you can easily end up with 2
> results that are the same unless the frequency with which you generate
> numbers is less than the variation you're introducing, and at that point
> why bother with the random number at all...

Oh yeah, I meant "concatenate" not "add".

Doing something like $random = $microtime . "_" . rand( 0, 256 );
gives you non-repeating pseudo-randomness. Whether that's random
enough for some applications is another issue, but it won't repeat as
long as the timestamp used for $microtime doesn't roll over to 0.
_______________________________________________
New York PHP User Group Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

http://www.nyphp.org/show_participation.php

Reply via email to