How does a computer calculate a 'random' number?

Soldato
Joined
28 Oct 2006
Posts
12,457
Location
Sufferlandria
Had an argument about computers and random numbers.
I said that pcs cannot make up random numbers, i was then 'proved wrong' ( :rolleyes: ) by someone making a short program that outputted a 'random' number.

Randomness requires creativity (intelligence) which computers do not have. So i assume they have some hugely complicated formula to calculate a random number. Does anybody know how its done?
 
touch said:
Randomness requires creativity (intelligence) which computers do not have.

Actually randomness requires freedom, which computers do not have.

Excuse the double post :o
 
Zefan said:
Actually randomness requires freedom, which computers do not have.

Excuse the double post :o


random numbers do work :D
i made a application that does exactly that
 
Did it use the time/date of the computer?

Even then it wouldn't be truely random, even if a calculation is unique it is still a calculation.
 
Last edited:
tsj said:
random numbers do work :D
i made a application that does exactly that

NO! A computer cannot make a random number!
Functions available in programming, like "rand()" are good at simulating random numbers, but its not truely random.

The only way i can think of getting a true random number from a computer would be something like reading tiny variances in its power supply or variances in cpu temp (things which are influenced by our analogue world rather than made by the digial computer)
 
Last edited:
touch said:
NO! A computer cannot make a random number!
Functions available in programming, like "rand()" are good at simulating random numbers, but its not truely random.

The only way i can think of getting a true random number from a computer would be something like reading tiny variances in its power supply or variances in cpu temp (things which are influenced by our analogue world rather than made by the digial computer)


http://computer.howstuffworks.com/question697.htm

good read for ya...
nerd ;)
 
haha, i'v explained this so many times today.

A computer can only do one thing: follow instructions.
You must tell it how to make the number, therefor its not a random number :/
 
Indeed, a computer cannot generate a truly random number; only a pseudo-random number. If you wanted a truly random number you'd have to use a physical source of some kind that exhibits random and entirely unpredictable behaviour (some quantum systems do this).
 
Last edited:
touch said:
Had an argument about computers and random numbers.
I said that pcs cannot make up random numbers, i was then 'proved wrong' ( :rolleyes: ) by someone making a short program that outputted a 'random' number.

Randomness requires creativity (intelligence) which computers do not have. So i assume they have some hugely complicated formula to calculate a random number. Does anybody know how its done?

It needs dedicated hardware to get truly random numbers - these usually use such notions as thermal noise or quantum oscillations.
 
touch said:
i was then 'proved wrong' ( :rolleyes: ) by someone making a short program that outputted a 'random' number.

If you ran it long enough then you would probably find that it started repeating its self. Most random number functions use an algorithm based on the current time in milliseconds. I've had a problem before with a multithreaded Java program with seperate threads running a random number generator in the same millisecond and getting the same number. For most applications however these methods are good enough
 
Software-based RNG's like MT19937 generate a 'statistically random' sequence of numbers, ie, algorithmically incompressible but they must be seeded with a truly random number to be different every time. A crypographically secure RNG such as /dev/random on Linux, in the absense of a real hardware RNG, uses multiple readings of indeterminate I/O timings to do this, such as timings between network packets, HD seeks, keystrokes and mouse movements.

The Intel 820 chipset has a thermal noise RNG accessable through conventional port I/O and the VIA-C3 processor has a special RNG instruction. Sometimes these can be slow, so are sometimes used purely to seed a faster, software-based RNG.
 
matja said:
Software-based RNG's like MT19937 generate a 'statistically random' sequence of numbers, ie, algorithmically incompressible but they must be seeded with a truly random number to be different every time. A crypographically secure RNG such as /dev/random on Linux, in the absense of a real hardware RNG, uses multiple readings of indeterminate I/O timings to do this, such as timings between network packets, HD seeks, keystrokes and mouse movements.

The Intel 820 chipset has a thermal noise RNG accessable through conventional port I/O and the VIA-C3 processor has a special RNG instruction. Sometimes these can be slow, so are sometimes used purely to seed a faster, software-based RNG.

Just to be clear on this though, its importamt to read enough data from your random source (such as /dev/random) to ensure that you have enough data to create truly random output.
 
We are already having problems building faster cpus because of issues at the quantum level. we could use this phenomenon to our advantage and build a hardware random number unit.
 
Inquisitor said:
If you wanted a truly random number you'd have to use a physical source of some kind that exhibits random and entirely unpredictable behaviour (some quantum systems do this).
If you want random and entirely unpredictable behaviour, you could always install an unpatched version of Windows and connect it to the 'net...
 
It depends upon the system needed.
Banks etc use random number generators which use random radioactive decay as their source of entropy.

I've seen systems using such diverse entropy sources as webcams of london traffic and lava lamps.

Of course there's also the XKCD way. ;)

Code:
function random() {
    return 4; // decided by random dice roll
}

Visage said:
Just to be clear on this though, its importamt to read enough data from your random source (such as /dev/random) to ensure that you have enough data to create truly random output.
/dev/random usually does this anyway, it blocks until it's sufficiently random. That's why /dev/urandom exists as a non blocking random source.
 
Last edited:
DaveF said:
If you want random and entirely unpredictable behaviour, you could always install an unpatched version of Windows and connect it to the 'net...

Or use the number in the "x minutes remaining" dialog box when you copy a file...
 
Back
Top Bottom