There are two concepts in software engineering related to this – “pseudorandom” and “true random”.
Pseudorandom numbers are always generated from a single deterministic “seed” (usually the current system time or a variant of it). Say you start with 5, and your algorithm is “multiply the last generated number by 2 and add 7”. So you will generate 5, 17, 41, 89, 185… These numbers at a glance may *seem* random, but if you know the seed value and the exact algorithm used you can always predict them. So this is exactly like what you described.
The thing is, most applications work just fine with such “random” numbers. Think shuffling songs on your playlist or playing a game. Unless the task involves security or something equally critical, it’s perfectly fine for such numbers to be deterministic to some degree.
On the other hand there is often a need for “true” random numbers, ones that cannot be predicted no matter what. In these cases computers use external sources of randomness. A combination of stuff like – you moving your mouse around the screen, packets received over the network, CPU temperature, Disk I/O, microphone noise, camera input. Sometimes computers can even have specialized hardware to generate randomness, e.g. by measuring radioactive decay.
Latest Answers