Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I'm not especially familiar with /dev/urandom but I understand that it can "run out" of randomness and have to wait for some more to be "collected". As such it should be used sparingly, but you're tossing out over 50% of the random chars that you fetch from it.

Since you wont be using high bit ascii, you could zero out the most significant bit, mapping it 1 to 1 with the low bit ascii. This would significantly reduce the amount of randomness that you have to throw out.

This works on my x86 linux machine.... endianness might matter, but I'm not sure.

read( R, $char, 1 ) or die "Failed to read 1 char from @{[SRC]}: $!\n" +; vec($char, 7 , 1) = 0; # map high-bit ascii to low-bit ascii
Update: As stefan k pointed out to me, /dev/urandom doesn't block when the entropy pool runs out. Instead, when no true random bits are available it will return pseudorandom bits instead. Its still probably a good idea to avoid pulling more bits than necessary though, just to keep the entropy pool happy and the pseudorandoms at bay ;-)

-Blake


In reply to Re: spew - print out random characters by blakem
in thread spew - print out random characters by grinder

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 musing on the Monastery: (4)
    As of 2014-08-31 00:29 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (294 votes), past polls