There's more than one way to do things PerlMonks

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

by stevieb (Canon)
 on Dec 31, 2016 at 00:08 UTC ( #1178711=note: print w/replies, xml ) Need Help??

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.

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1178711]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2023-06-09 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How often do you go to conferences?

Results (35 votes). Check out past polls.

Notices?