There's more than one way to do things PerlMonks

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

by BrowserUk (Patriarch)
 on Dec 31, 2016 at 03:10 UTC Need Help??

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.
• Comment on Re^6: rand() function on Windows systems (pure Perl)

Replies are listed 'Best First'.
Re^7: rand() function on Windows systems (pure Perl)
by bakiperl (Beadle) on Dec 31, 2016 at 16:10 UTC

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;
}

You might just as well do:

```my \$seed = 555;
...

It amounts to the same thing.

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.

Hm. srand always returns 1 regardless of its argument on my system:

```print srand( \$_ ) for 1 .. 10;;
1
1
1
1
1
1
1
1
1
1

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 strange. I get the same result on my systems using old and new versions of Perl.

```print srand( \$_ )."\n" for 1 .. 10;;
1
2
3
4
5
6
7
8
9
10

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-16 20:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found