Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Use Bytes::Random::Secure. Seeding is superior, the CSPRNG is ISAAC, and its random_string_from function does exactly what you want, with very few dependencies.

use Bytes::Random::Secure qw( random_string_from ); my $string = random_string_from( join( '', ( 'a' .. 'z' ), ( 'A' .. 'Z' ), ( '0' .. '9' ) ), 56 ); print $string, "\n"; # Done; no md5 bias, no modulo bias, strong seeding, strong CSPRNG.

Update: I didn't have time to elaborate earlier. But the point here is that seeding correctly is hard. Generating strong pseudo-randomness is hard. But this is a problem that has been solved already (on CPAN), with a good deal of research, and collaboration. And to get well seeded, high quality random bytes, you need one module, which has exactly three non-core dependencies in its heritage, if you exclude what Test::Warn drags along with it. ...and it works portably across many platforms, and back through Perl 5.8. In some cases even 5.6.

As others have mentioned there are flaws in the seeding you're using. And an MD5 RNG is less than ideal.


In reply to Re: Custom-length random/unique string generator by davido
in thread 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 the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (7)
    As of 2018-11-17 15:05 GMT
    Find Nodes?
      Voting Booth?
      My code is most likely broken because:

      Results (204 votes). Check out past polls.