Perl: the Markov chain saw | |
PerlMonks |
Randomness (was Re: Re: Re: Use time() to create unique ID)by blue_cowdawg (Monsignor) |
on Sep 16, 2003 at 17:57 UTC ( [id://291903]=note: print w/replies, xml ) | Need Help?? |
Let's not get hung up in the difference between the practical and the theoretical here. :-) For the purposes stated by the OP using rand() is "good enough." Also based on my own practical use using this method to generate unique session ids for web transactions I have found that it works very well. When using this method in my own applications I have very deliberately set up trapping logic checking to make sure that a generated session id is not already in use and if it ever happens the logic logs the incident. The log is still empty for one application I use it for and that web application was installed in August of 2001. Over two years now and no collisions. I think that works pretty darn good. Truly random and unique idsThe one time I needed to generate truly random numbers for an application I wrote (I could tell you what it was but then I'd have to shoot you) :) I decided the best way to do it was taking a page from PGP and GNUpg and use system entropy. Stuff like watching the position of the system disk heads, being influenced by system interrupts (mouse, keyboard, etc.) and stuff like that. You can make yourself nuts with the whole subject and folks a lot smarter than me have made their academic mark on the world writing papers on the subject and there is even a whole field science dedicated to the subject. For practical purposes you have to make a decision as to what constitutes "random enough" and code accordingly. A random ID of 128 characters is probably going to be random enough for 99% of the uses out there . But then... we are getting way off topic here...
In Section
Seekers of Perl Wisdom
|
|