Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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!

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

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (3)
    As of 2018-01-24 11:55 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (258 votes). Check out past polls.