Now fixed (see modified code and new output below) on ActivePerl, thanks to the previous replies. Has this been a common problem in ActivePerl? I'm pretty new to this, and naively thought the rand function would be platform independent.
$seed = rand(100); for ($x=10; $x<10000000; $x=$x*10){ $error_rate = $x; print "Error rate = 1 every $x, errors = "; for ($y=0;$y<5;$y++){ errortest(); } print "\n"; } sub errortest { $errors = 0; for ($n=0;$n<1000000;$n++){ $random = int (better_random($error_rate)); if ($random == 1){$errors++} } print $errors, " "; } sub better_random { $seed = ($seed * 65539) % 2 ** 31; $this_random = $_[0] * ($seed / 2 ** 31); return $this_random; } Ouput: Error rate = 1 every 10, errors = 99259 100049 99986 99998 99818 Error rate = 1 every 100, errors = 10166 10098 10056 10107 10032 Error rate = 1 every 1000, errors = 967 1013 1009 948 1004 Error rate = 1 every 10000, errors = 96 108 112 116 104 Error rate = 1 every 100000, errors = 16 11 7 8 10 Error rate = 1 every 1000000, errors = 0 3 1 1 0

In reply to Re: Re: Re: Math all gone wrong... by carlos fandango
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.