chrishoffman at February 22nd, 2014 06:40 — #1
Originally published at: http://www.howtogeek.com/183051/htg-explains-how-computers-generate-random-numbers/
Computers generate random number for everything from cryptography to video games and gambling. There are two categories of random numbers — “true” random numbers and pseudorandom numbers — and the difference is important for the security of encryption systems.
nsdcars5 at February 22nd, 2014 08:56 — #2
The perfect random number generation algorithm:
bben at February 22nd, 2014 08:56 — #3
Many years ago in one of my first computer courses ( around 1978) One assignment included a random number generator in FORTRAN. The instructor was going to grade partially based on how many iterations it would go before beginning to repeat. Most students used a variation on a large prime number for their seed as that was what the book showed as the way to do it. For my seed, I used the system clock. Every time it needed a random number, it did a call to the clock for a new seed. My generator was still going long after every one else was into repeating. The instructor finally stopped it and it was still not repeating. The next year, he used my solution to show how a pseudo random number generator could be made into a true random number generator.
wilsontp at February 22nd, 2014 17:18 — #4
Using the system time has always been one way to create a more random seed; we were learning that back in the 80's. The trouble is that the sequence is still not truly random. This is "pseudo-random", since the outcome is still deterministic. It's possible to predict the outcome of your random number roll if you know the system time.
If you want a truly random number, you need to interact with something outside the computer. One way to do this is with the sound card's microphone. Even if you don't have a mic plugged in, it's still possible to get white noise through the mic preamp. You take a few samples from the microphone port and use those as part of your seed. Or have a person press a key on the keyboard when a symbol flashes on the screen. No matter how good they are, there will be a non-deterministic delay between the time the symbol appears and the time the key is fully depressed.
There are other ways of interfacing with the real world, as well: radio receivers, video cameras, even sensors that can detect radioactive decay. You could record mouse movement on the screen or use the location of a GPS device on he APRS network
The key is getting outside the processor and in to the real world. Once you leave the digital domain, randomness abounds.
nsdcars5 at February 22nd, 2014 23:42 — #5
How about the system generates random numbers on the basis of the attributes (their number, size, permissions, filename and extension, etc.) of all the files in all the drives connected to the computer? That might be pseudo-random too (attacker might have a cloned copy of your HDD), but probably unlikely to be found to be in a pattern easily.
Alternatively, when /dev/random runs out of stuff, start timing the time till it gets more stuff. Those times can't always be the same.
bben at February 23rd, 2014 06:43 — #6
With the time sharing we had to work with on that old Data General Eclipse, the program would be paused every few seconds for a higher priority program to run - this had the effect of changing the seed over time. Also, there was some clock drift that helped keep it random. This was in 1978 - computer clocks were not quite as stable. Especially out in about 8 decimal places. You really don't need much drift to get an actual random output. I like the idea of using white noise to generate a seed also. But that would have required some external input that we didn't have access to at that time. There was no audio involved in that computer. Later, after school, I hooked all kinds of devices up to various computers, The only time I needed a random number generator was for a D&D dice rolling prog I wrote in Basic on a DEC VT78 I had at home. As it ran in real time, and didn't read the clock until a key was pressed it worked fine for my application. You need to roll 2d7? we can do that.
wilsontp at February 23rd, 2014 18:48 — #7
@bben actually, I missed the part where you were doing that in 1978.
I had the same experience in my first computer class in 1982. We were coding a hi-low game, and I noticed that no only did I get the same sequence every time, but that the sequence was the same on all of the computers in the lab. Since then, I've always been on the lookout for a better random number algorithm, and that's why I became interested in the idea of using real-world data to seed the algorithm.
In an ideal world, a computer would have a built-in analog component that generates a truly random value, then uses that whenever someone calls the Rand() function. I'm kind of surprised that, with more than 50 years of computer science behind us, the industry still hasn't build a standard device for that vital purpose.
raphoenix at February 23rd, 2014 20:13 — #8
True random numbers to anyone on the Internet. The randomness comes from atmospheric noise, which for many purposes is better than the pseudo-random number algorithms typically used in computer programs.
system at March 4th, 2014 06:40 — #9
This topic was automatically closed after 10 days. New replies are no longer allowed.