Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^2: JAPH randomness

by awwaiid (Friar)
on Feb 02, 2005 at 07:17 UTC ( #427173=note: print w/replies, xml ) Need Help??

in reply to Re: JAPH randomness
in thread JAPH randomness

So the issue, as I mentioned previously, is whether your perl and my perl have the same random number generator. Heres one way to check:

perl -e 'srand(0);print rand(100)."\n"'

When I run this I get 17.082803610629. What do you get?

Let us know if it works at home! :)

Replies are listed 'Best First'.
Re^3: JAPH randomness
by wolfger (Deacon) on Feb 02, 2005 at 14:40 UTC

    I get 0.115966796875 on my laptop. I forgot to try at home.
    So let me get this straight... We can "initialize" the random number generator such that the numbers are not random whatsoever, but rather completely predictable? Very interesting.

    Linux, sci-fi, and Nat Torkington, all at Penguicon 3.0
    perl -e 'print(map(chr,(0x4a,0x41,0x50,0x48,0xa)))'

      *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!

        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)))'

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2021-09-28 03:38 GMT
Find Nodes?
    Voting Booth?

    No recent polls found