Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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.
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 ); }
Your suggestions for code improvement are most welcome!
Sincerely,
~RecursionBane

In reply to Custom-length random/unique string generator by RecursionBane

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (6)
    As of 2014-04-19 10:20 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (480 votes), past polls