Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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

by bakiperl (Beadle)
on Dec 30, 2016 at 23:23 UTC ( #1178710=note: print w/replies, xml ) Need Help??

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

Wow! This is even better. Thank you.
  • 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)(Correction)
by BrowserUk (Patriarch) on Jan 01, 2017 at 19:12 UTC

    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.

      Great job man! This last fix cleared all my problems.

      Thank you again.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1178710]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2023-05-28 12:58 GMT
Find Nodes?
    Voting Booth?

    No recent polls found