How can computers perform random operations?

There might be an embarassingly easy explaination for this question (i apologize if it’s been covered–i’m new), but it has always baffled me. If a computer is designed to do exactly what it is told, how can it generate a random number or outcome? Would any results be “absolutely” random or just an approximation? Are there degrees of random-osity? I can clarify my question further if you’re confused…

In programming (VB, C++, etc.) computers don’t perform random number generation. You have to provide a “seed” number to generate a psuedo-random result. A good choice is to use the number of milliseconds in the present system time. Since it is constantly changing, and you really can’t peg it down to any instant, it should simulate a random number for you.

Zev Steinhardt

‘Random’ numbers from computers are not truly random. They are the result of a group of complex calculations, but if you know the number they start from and the operations involved, you can always predict the result. Thus, they are not strictly random.

But, they can be a very good approximation of true randomness. What they do is use a ‘seed number’ that is unpredictable. Often, this will be something like the number of milliseconds the computer has been running, or the exact number of clock cycles between noon and when the user hits a key. That value is almost random, so the result is also ‘almost’ random.

The short answer is: they don’t. The previous two posters explained about seed numbers. That type of randomness does very well. However, for doing things like generating random keys for cryptography, you need REAL randomness, in which case the computer looks at things from nature, like the least significant numbers in the acceleration of a mouse, times of taps between keys, or times between beta particles flying off radioactive stuff.

As friedo said, for high-quality random numbers, you need a hardware implementation. It’s not too difficult to get a few random numbers via mouse click or keyboard timing, etc., but for a continuous stream you need something like this:

http://www-3.ibm.com/security/cryptocards/

It’s actually pretty difficult to build a really good random number generator in hardware, also, especially if you need a high-data rate stream.

Arjuna34

For more than you probably wanted to know about pseudo-random numbers (the kind a deterministic computer program generates), try chapter 7 from this link:

http://www.ulib.org/webRoot/Books/Numerical_Recipes/bookcpdf.html

Arjuna34

I used to program models for systems that required a random element. The pseudo-random would be used for a while, then the “real random” was needed. We couldn’t gain any confidence that random numbers were actually produced, so we plotted them. There were obvious patterns developing, that would repeat. So, we resorted to sampling the small electrical current with our probe board and just keeping the least significant digits. This proved satisfactory.

Actually, Intel added a hardware random number generator starting with Pentium III. According to one document:

Thermal noise is just electrons moving around randomly on a wire, like Brownian motion of little particles floating on water. Thermal noise is truly random.

If I need a really random number (and who doesn’t on occasion?), I get my computer drunk!

A good alternative to this (if you can’t afford to give your computer a hangover) is to ask your girlfriend the following: “Honey, is it easier to tie your shoes being that short?” Wait a few miliseconds, and she’ll whop you over the head with your keyboard… guaranteed to generate lots of random numbers!

The problem with thermal noise is pickup of surrounding signals, such as PC clock, bus noise, etc. This tends to synchronize the “random” thermal noise with outside events, corrupting the randomness. The thermal noise itself is still random, but superimposed on top is non-random noise. It CAN be done, but it’s tricky to do it right :slight_smile:

Arjuna34

As a historical note, there used to be published books of random numbers. I think I recall seeing a set of random number tables in an old edition of the “CRC Rubber Tables” book, which is a standard refererance familiar to any physicist or chemist. I don’t know how these were generated, it must have been a real bitch to produce random numbers manually, with enough true randomness to satisfy picky physicists.

Nah, thermal noise is definitely NOT “doing it right.” You need a more reliable random phenomenon.
I recall seeing an article many years ago (Ciarcia’s Circuit Cellar IIRC) that used radioactive decay as the random element. It detected particles emitted from a small sample of a radioactive element and used that to generate random numbers. Now THAT is how to generate a random number.

I agree, radioactive decay is a bettery source than thermal noise, but I don’t think it’s easy to get a 10 MB/s random stream out of it :slight_smile: Especially if it’s going into the slot of a PC sitting at waist level :wink:

Arjuna34

Here’s a site that uses lava lamps to generate randoms.
http://lavarand.sgi.com

Why is thermal noise not a good source of random numbers?

In an ideal situation thermal noise would be fine. This ideal situation would have a thermal noise generating element (i.e. a resistor or diode) at a constant temperature, with no outside RF or other noise hitting it. Also, to measure the noise on the device, an infinite impedance voltage (or zero impedance current) measuring circuit would be used.

In real life, the device isn’t at a constant temperature- it’s fluctuating, which affects the stream of random numbers. Also, the circuit measuring the noise has some effect on the noise. Outside sources of noise can grow large enough to interfere with the random noise element. It’s not impossible to manage, but it’s not real simple to make a really good thermal noise random number generator. It’s very easy to make a half-way decent one, though, which kept in its own shield box outside of a noisy PC, is OK for many purposes.

The advantage of radioactive decay is that most outside influences have absolutely no affect on the decay rate.

Arjuna34

Would a lava lamp be really random though? One wonders if it couldn’t end up with patterns imposed, much like in the case of the PIII.

How about this? Maybe levels of radon gas seeping into houses varies based upon temperature/time of day. (soil expansion, or air temperature) The radioactive gas then slightly screws up the random number generator in a predictable pattern. :slight_smile:

Um, well, I did say “most” :slight_smile:
You’d have to shield against that too, but since radon gives off alpha particles, it would be pretty easy.

Arjuna34

Just be sure not to try to generate random numbers during, say, the Academy Awards or the Super Bowl. See The Conscious Universe.