RecursionBane has asked for the wisdom of the Perl Monks concerning the following question:
Your suggestions for code improvement are most welcome!sub generate_unique_id { # Creates and returns a "random" string of 56 alphanumeric # Usage: generate_unique_id() # This includes [a-z] [A-Z] [0-9], a range of 62 characters # The random number generator is seeded elsewhere with a permutati +on of this child's process ID and current machine time my $buildID = md5_base64 ( rand($$) ) . md5_base64 ( rand($$) ) . +md5_base64 ( rand($$) ); # Strip out "+" and "/" $buildID =~ s/\+//g; $buildID =~ s/\///g; # Truncate to fifty six characters (this is 2.4e+100 possible comb +inations, or approximately two googol) # It would take 187 sesvigintillion (187e+81) years at 4 billion b +uilds/second for a conflict to arise, which makes it a fairly unique +buildID return substr ($buildID, -56 ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Custom-length random/unique string generator
by davido (Cardinal) on Feb 02, 2013 at 17:30 UTC | |
|
Re: Custom-length random/unique string generator
by martell (Hermit) on Feb 02, 2013 at 18:13 UTC | |
|
Re: Custom-length random/unique string generator
by BrowserUk (Patriarch) on Feb 02, 2013 at 19:33 UTC | |
|
Re: Custom-length random/unique string generator
by Athanasius (Archbishop) on Feb 02, 2013 at 17:43 UTC | |
|
Re: Custom-length random/unique string generator
by RichardK (Parson) on Feb 02, 2013 at 19:42 UTC | |
|
Re: Custom-length random/unique string generator
by RecursionBane (Beadle) on Mar 21, 2013 at 19:02 UTC |