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


in reply to Re: rand() function on Windows systems
in thread rand() function on Windows systems

Yes. That did the trick.

Thank you BrowserUk

Replies are listed 'Best First'.
Re^3: rand() function on Windows systems (pure Perl)
by BrowserUk (Patriarch) on Dec 30, 2016 at 21:57 UTC

    Just for completeness, this pure perl version should also work:

    { my $seed; sub ppSrand{ $seed = int( $_[ 0 ] & 32767 ); } sub ppRand{ my $max = shift // 1; $seed = ( $seed * 214013 + 2531011 ); return ( ( $seed >> 16 ) & 32767 ) / 32768 * $max; ## Amend +ed per post below. } } ppSrand( 555 ); print int ppRand( 1000 );

    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.
      Thanks, BrowserUK. I have a low priority project which has been on hold for several years awaiting a solution to the problem described by the OP. Somehow, I overlooked the possibility of writing a generator. (The quality of the sequence is not an issue.) Your solution seems perfect!
      Bill
      Wow! This is even better. Thank you.

        Hm. I forgot that Perl would upgrade the seed to a float; that needs to be clamped back to a 32-bit integer as the new line below:

        { my $seed; sub ppSrand{ $seed = int( $_[ 0 ] & 32767 ); } sub ppRand{ my $max = shift // 1; $seed = ( $seed * 214013 + 2531011 ); $seed &= 0xffffffff; return ( ( $seed >> 16 ) & 32767 ) / 32768 * $max; } }

        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.

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

        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.
        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.