in reply to What's the best way to avoid name collisions when creating files?

I just use random strings, with this sub I found by searching PerlMonks:
sub rndlc{local$"=''; "@{[map{chr(97+int rand 26)} 1 .. shift]}" }; my $filename = rndlc(10);
You can always attach the random string at the end of a date-time string to get more human-friendly filenames.

Of course there's no guarantee you won't get the same string twice, but the odds are 2610 against it...



($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
=~y~b-v~a-z~s; print
  • Comment on Re: What's the best way to avoid name collisions when creating files?
  • Download Code

Replies are listed 'Best First'.
Re^2: What's the best way to avoid name collisions when creating files?
by DrHyde (Prior) on May 03, 2005 at 09:03 UTC
    You are assuming that the random number generator's results are evenly distributed. You might like to check the quality of rand's results using Statistics::ChiSquare.