What makes you think the same sequence repeats? The existence of like named files does not imply they were generated in the same sequence.
Lets say that on one day rand() produced the sequence a,b,c,d,e,f,g,h,i,j. The next day it might produce the sequence c,h,a,e,g,b,i,d,f,j. This would not be the same sequence, but would still boggle your name generator. If the length of your filenames aren't limited other than the OS limitation, I'd use the PID ($$), time(), and a rand() to generate the file name. If, for some reason, you need to conserve the number of characters used, represent them in hex, or better yet, base64. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Chris Wagner Sent: Friday, December 02, 2005 3:14 AM To: Perl-Win32-Users@listserv.ActiveState.com Subject: Re: rand() not so random At 01:54 PM 12/1/2005 -0500, [EMAIL PROTECTED] wrote: >2. A random number generator can generate duplicates and still be >random (of course it could also be repeating). Indeed, a random number >generator should, in general, generate duplicates. It is a special case >of random number generation where duplicates are not allowed. Right, I anticipated this by checking whether the filename already existed. I never expected that duplicates were impossible. >5. Using a random number generator to generate unique files names seems >kind of odd. Why not use the date and time plus -e file operator and a >little character string magic (auto-increment a character string with >++) to generate the file names? I guess in my zeal to show the weakness of the rand() function I've distracted myself and everybody from the real problem. I can even accept 2^15 as the number domain. Let's refocus. The real problem is that on Monday it can spit out a sequence of numbers x, y, z, a, b, c. Then three days later it can spit out the exact same sequence x, y, z, a, b, c. This seems very wrong. The concept of randomness means that the order cannot be predicted and has no pattern. In this case however, the sequence *repeats*. Even in a small 2^15 domain, no sequence should repeat. Remember this is a mod_perl script that is always "on". -- REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=-- "...ne cede malis" 00000100 _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs