Naked Science Forum

Non Life Sciences => Geek Speak => Topic started by: bizerl on 15/02/2013 04:15:08

Title: How does a computer generate a random number?
Post by: bizerl on 15/02/2013 04:15:08
Or how does my ipod decide what order to play songs when I "shuffle"?

Is it truly "random" or is there always a pattern?
Title: Re: How does a computer generate a random number?
Post by: CliffordK on 15/02/2013 06:31:21
Most computers will use some type of a pseudorandom number generator (http://en.wikipedia.org/wiki/Pseudorandom_number_generator)

The key is to get a "seed" such as the time of the clock that would be different, and not produce the same starting point every time the program is restarted.  Or, perhaps, remember the last number accessed in the sequence.

For an IPOD, a true random number may not be an issue.

There is a concern that games of chance with money involved, such of state lotteries could be compromised by poorly written pseudorandom number generators.
Title: Re: How does a computer generate a random number?
Post by: evan_au on 15/02/2013 09:42:01
Humans are very good at seeing patterns where there is no pattern.

With the iPod, early versions selected the next song truly at random (in software) - but sometimes a truly random selection will play the same song twice in a row, or (even more likely) twice in the same hour. People complained, and so the song selection was made less random, by avoiding recently played songs, which perversely made people feel that it was more random! You can now select the degree of randomness that you want. http://electronics.howstuffworks.com/ipod-shuffle2.htm

There are severe limitations of software random number generators;  computer pioneer John von Neumann said that "Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin."

Intel is designing a hardware random number generator into new CPUs, which will make it effectively impossible to predict the next random number without hacking the computer. http://spectrum.ieee.org/computing/hardware/behind-intels-new-randomnumber-generator/0
Title: Re: How does a computer generate a random number?
Post by: RD on 15/02/2013 14:14:30
some computers use thermal noise to generate truly random numbers ...
http://en.wikipedia.org/wiki/Hardware_random_number_generator