in reply to Re^6: Generate a unique ID
in thread Generate a unique ID
Consider the following practical algorithm:
sub random_string { my $self = shift; my $result = shift; $result = '' unless (defined($result)); my @letters = ('A'..'Z', 'a'..'z'); my @letternum = ('A'..'Z', 'a'..'z', '0'..'9'); # PRODUCES RANDOM ALPHANUMERIC IDENT 8 CHARS LONG, FIRST CHAR ALPHA. $result .= $letters[rand $#letters]; $result .= join "", map { $letternum[rand $#letternum] } 1..7; return $result; }
One million repetitions later, the same string was never produced twice. I am quite confident that, if I had ten or even a hundred times as much time to waste waiting for Godot to repeat himself, the result would have been exactly the same. So, I think that it is quite defensible to say, “it ain’t nevah gonna” happen. Once you have reduced the probability acceptably close to zero (and of course, have demonstrated in your test-suite that it is, in fact, robust), then ...
“Well, that’s close enough to zero for peace work ...”
Replies are listed 'Best First'. | |
---|---|
Re^8: Generate a unique ID
by BrowserUk (Patriarch) on Nov 17, 2010 at 17:58 UTC |
In Section
Seekers of Perl Wisdom