Nice tricks, but if compressibility can serve as measure of entropy, then your output is not very random. (Output here is single buffer with newlines inserted after every 64 hex digits. Perhaps close enough for simulation. And ~50% compression of hex digits as opposed to raw bytes indicates pretty much "white noise" i.e. randomness.) The Math::Prime::Util::GMP claims its random_bytes to be the fastest of all, maybe it's not too slow for you. And, I agree, rand/pack combo of built-ins is very slow for the case, indeed.

use strict; use warnings; use Benchmark 'cmpthese'; use Math::Prime::Util::GMP 'random_bytes'; use IO::Compress::Deflate; sub original { my $buf = random_bytes(32); my $ret = ''; # Negate bits for my $bytes ($buf, ~$buf) { # Reverse bits for my $bits ($bytes, pack('b*', unpack 'B*', $bytes)) { # Reverse nibbles for my $hex (unpack("H*", $bits), unpack("h*", $bits)) { # Reverse hex string for my $str ($hex, scalar reverse $hex) { $ret .= $str . "\n"; # Rotate hex string $ret .= substr($str, $_) . substr($str, 0, $_) . " +\n" for 1 .. 63; } } } } $ret; } sub random { ( join "\n", unpack '(H64)*', random_bytes(32768) ) . "\n" } cmpthese -1, { original => \&original, random => \&random, }; print "\n"; my $z = IO::Compress::Deflate->new( \my $s1 ); $z->print( original() ) for 1 .. 1000; $z->close; my $ratio = 100*( length $s1 )/( 65*1024*1000 ); printf "original output compressed to %.1f%%\n", $ratio; $z = IO::Compress::Deflate->new( \my $s2 ); $z->print( random() ) for 1 .. 1000; $z->close; $ratio = 100*( length $s2 )/( 65*1024*1000 ); printf "random output compressed to %.1f%%\n", $ratio;

...

Rate random original random 2589/s -- -65% original 7440/s 187% -- original output compressed to 5.2% random output compressed to 57.7%

In reply to Re: Increasing throughput of random data by Anonymous Monk
in thread Increasing throughput of random data by Anonymous Monk

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!
  • 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, details, 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, summary, 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.