http://qs1969.pair.com?node_id=1178711


in reply to Re^3: rand() function on Windows systems (pure Perl)
in thread rand() function on Windows systems

That's very nice. I'm glad we have statistical analysts/mathematicians here.

  • Comment on Re^4: rand() function on Windows systems (pure Perl)

Replies are listed 'Best First'.
Re^5: rand() function on Windows systems (pure Perl)
by bakiperl (Beadle) on Dec 31, 2016 at 02:59 UTC
    Small correction in the code above:

    This line of code :

    return ( ( $seed >> 16 ) & 32767 ) / 32767 * $max;

    should be:

    return ( ( $seed >> 16 ) & 32767 ) / 32768 * $max;
    The difference can be seen if you don't use the integer (int) function.
      The difference can be seen if you don't use the integer (int) function.

      You are absolutely correct++!


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
      In the absence of evidence, opinion is indistinguishable from prejudice.

        One more thing.

        Apparently, the random number seed sub is not necessary the srand operator works the same between the old and the new versions. The simplified code below is enough.

        my $seed = srand( 555 ); print ppRand( ), "\n"; sub ppRand { my $max = shift || 1; $seed = ( $seed * 214013 + 2531011 ); return ( ( $seed >> 16 ) & 32767 ) / 32768 * $max; }
Re^5: rand() function on Windows systems (pure Perl)
by BrowserUk (Patriarch) on Dec 31, 2016 at 01:15 UTC
    I'm glad we have statistical analysts/mathematicians here.

    He he. I am abysmal at statistics -- it is the second most unintuitive subject on the planet -- and I am to a mathematician, what a draughtsman is to an artist.

    I did a search and found this, the conversion to Perl was trivial :)


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
    In the absence of evidence, opinion is indistinguishable from prejudice.