A little thought about the source of randomness (entropy) indicates that this is unlikely to be a very good random number source. The "randomness" comes from the variable time it takes to execute a loop, so what causes the reported loop execution time to change? Well, in a modern multi-tasking operating system most of the variation will be due to other tasks running during the loop time. So the processor running your for loop will potentially "slice" its time between several tasks. The important factor is, how consistent are the slice times?

On busy systems with internet browser windows open or various other tasks interacting with the real world there will be a range of slice times because the real world interactions introduce a fair whack of entropy. On quiet systems there will be only a small variation in slice times because the only "random" stuff going on will be things like the real time clock interrupt so there will be very little entropy introduced and the random number generated will be poor.

Note that measuring the quality of random numbers is hard and requires some fairly high powered maths and statistical techniques. Depending on your use for the numbers, correlations between numbers in a sequence can be al least as important a measure as the actual distribution of the numbers. I would be exceedingly surprised if your simple TRNG actually generates statistically robust random number sequences.

If the code changes take longer than the time saved, it's fast enough already.

In reply to Re: TRNG Perl script query by GrandFather
in thread TRNG Perl script query by tim.qfs

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.