Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: is rand() random

by jeffenstein (Friar)
on Jun 19, 2002 at 13:56 UTC ( #175680=note: print w/replies, xml ) Need Help??


in reply to is rand() random

rand() uses (IIRC) the built-in rand() function on your platform. This is a pseudo-random number generator, not true random numbers. Perhaps the rand() function is not up to snuff on your OS.

BTW, random doesn't neccessarily mean no duplicates. The sequence 5 5 5 5 5 is just as likely as the sequence 3 2 4 1 5 or 1 2 3 4 5. It just doesn't look random to us humans, who are wired for pattern recognition.

Replies are listed 'Best First'.
Re(2): is rand() random
by FoxtrotUniform (Prior) on Jun 19, 2002 at 15:36 UTC
      rand() uses (IIRC) the built-in rand() function on your platform.

    More to the point, stdlib rand() functions tend to be abysmally poor at generating even remotely random numbers (for both statistical and cryptographic definitions of "random"). Math::Random and Math::TrulyRandom are both good places to look for randomness in Perl, but coding up your own PRNG isn't terribly taxing, and a lot of fun.

    --
    The hell with paco, vote for Erudil!
    :wq

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2020-11-30 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?