"be consistent" | |
PerlMonks |
RE: RE: RE: Randomizing Unique ID?by tye (Sage) |
on Aug 10, 2000 at 00:51 UTC ( [id://27194]=note: print w/replies, xml ) | Need Help?? |
The rand() solutions are nearly as predictable, since rand() is deterministic and the latest Perl's seed function is deterministic based on $$, time(), and PL_stack_sp (except on some platforms). That last value, at the time it is checked, is probably often constant across invocations of the same script. The odds are much worse than 1/10^31 as the entire sequence from rand() is deterministic based on the seed. Perhaps you meant 1/2^32, which presumes a completely random seed, which you don't have. If you want to avoid predictability, then use Math::TrulyRandom (or encrypt using a secret key, if you think you can keep it secret) as others suggested. At least Perl has a much better seed generator these days. Also, even 1/2^31 would be the odds of a single duplicate. If you have lots of IDs with overlapping lifetimes, then the odds rise surprising fast. If you rarely have more than a few IDs active at once, then 1/2^31 might well be acceptable. But if it is possible, for example, to have 6600 simultaneous IDs, you get about a 1% chance of a collisions per batch of IDs; which probably isn't acceptable. - tye (but my friends call me "Tye")
In Section
Seekers of Perl Wisdom
|
|