Just another Perl shrine PerlMonks

### Re^4: JAPH randomness

by awwaiid (Friar)
 on Feb 03, 2005 at 15:23 UTC ( #427672=note: print w/replies, xml ) Need Help??

in reply to Re^3: JAPH randomness

*BIG SMILE*

Welcome, my friend, to the world of pseudo-random number generators! One of the best things about computers is that they are (supposed to be) deterministic; so random number generators are based on neat mathematical equations which appear random to an observer. You start with a seed, and then each number generated is based on the number(s) which have already been generated, going back to the seed.

Now, not all of these pseudo-random number generator algorithms are as "random" as others (see Knuth's work for example). Not long ago I had a Commodore-128 on which I was doing some lottery simulations and statistics to see if I could predict the lottery. I got stunningly good results... but as it turns out it was a weakness in the built-in random-number generating algorithm, not a weakness in the lottery :)

In any case, one thing that most of the pseudo-random number generators have in common is the seed. You give it the same seed, you get the same sequence of random numbers. All sorts of fun follow that. If you don't specify the seed one is created for you, based off of timing-based things like the clock and the PIDs and things like that (see function srand)

Our pseudo-random number generating days are most certainly limited, however. Hardware-based random number generators are increasingly innexpensive, and I doubt it will take long before all devices which need a random-number (all desktops for example) have one built-in. These are based on random numbers generated from physics... sort of the opposite of the timing accuracy of your quartz watch. Some are even based on magical quantum physics stuff...

I love living in the future!

Replies are listed 'Best First'.
Re^5: JAPH randomness
by wolfger (Deacon) on Feb 03, 2005 at 15:34 UTC

I knew computer randomizers were pseudo-random, it just surprised me how pseudo it was, to be able to seed the generator and come up with the same number every single time. I thought that on a system running multiple processes, the length of time to execute commands would vary marginally to produce a set (3, 6?) of "random" numbers that reliably comes up.
Hopefully the days of truly random numbers on computers comes soon.

--
Linux, sci-fi, and Nat Torkington, all at Penguicon 3.0
perl -e 'print(map(chr,(0x4a,0x41,0x50,0x48,0xa)))'
OTOH, seeding the random number generator to allways get back the same results is very handy during testing.
```--
#!/usr/bin/perl
for(ref bless{},just'another'perl'hacker){s-:+-\$"-g&&print\$_.\$/}

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2021-09-18 17:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?