Some insight knowledge of how ANSI C generates random numbers on a 32-bit machine:

this_seed = (last_seed * 69069) % 2 ** 32; (equation 1)

this_random_number = this_seed / 2 ** 32; (equation 2)

Every time you call rand, it first generates a new seed according to quation 1, then generates the random number following equation 2.

You can determine the initial seed by calling srand.

This is just how ANSI C does it. Obviously there are other ways.

Want more? Try the following set of equations, which belongs to the same "family" (this is the term we used to group algorithms generating random numbers, as you can see this family is linear) as the above set:

this_seed = (last_seed * 65539) % 2 ** 31; (equation 1)

this_random_number = this_seed / 2 ** 31; (equation 2)


In reply to Re: Math all gone wrong... by pg
in thread Math all gone wrong... by carlos fandango

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.