Beefy Boxes and Bandwidth Generously Provided by pair Networks
"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??


in reply to RE: RE: Randomizing Unique ID?
in thread Randomizing Unique ID?

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")

Replies are listed 'Best First'.
RE: RE: RE: RE: Randomizing Unique ID?
by turnstep (Parson) on Aug 10, 2000 at 16:28 UTC
    Good point regarding the deterministic sequence by using rand. In that case, bump the number of characters up to 16, or even 32 (which I've seen in a few URLs). Should be much better odds then (it's too early to actually calculate them now :)

      No, the number of characters doesn't matter (after a certain point). You could generate 200,000 characters and that wouldn't be any more random or less predictable than if you generated 100 characters because you only have (at most) 2^32 possible seed values and each seed value will produce the exact same sequence, no matter how long you make it.

      Update: To be more precise, if selecting from a set of 64 characters, then using 6 characters gives you 2^36 possible strings. So using more than 6 characters is useless if you have only 2^32 possible seed values.

              - tye (but my friends call me "Tye")

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://27194]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 16:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found