RecursionBane has asked for the wisdom of the Perl Monks concerning the following question:
Greetings, Monks!
I would like your opinion on any weaknesses in this (sufficiently random) random string generator in order to build universally unique identifiers (UUIDs). These UUIDs are used only on the local network to identify frequent build processes, where each build should be individually addressable.
I understand that there are several CPAN modules claiming to provide near-random numbers and even UUIDs, but I'm looking for an alphanumeric string, so I went with a simple, custom approach.
Sincerely,
~RecursionBane
I would like your opinion on any weaknesses in this (sufficiently random) random string generator in order to build universally unique identifiers (UUIDs). These UUIDs are used only on the local network to identify frequent build processes, where each build should be individually addressable.
I understand that there are several CPAN modules claiming to provide near-random numbers and even UUIDs, but I'm looking for an alphanumeric string, so I went with a simple, custom approach.
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 ); }
Sincerely,
~RecursionBane
|
---|
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 |
Back to
Seekers of Perl Wisdom