DEV Community

Discussion on: How can you make computer generate a random number without using algorithm just like our brain do.

Collapse
 
maruru profile image
Marco Alka

There are different types of randomness to random numbers. Usually, we differentiate between pseudo random numbers and true random numbers. Pseudo random numbers are generated by using an algorithm, which takes many factors into one formula to come up with a number.

You could use the current time in ns, the current CPU frequency, the current GPU temperature, the uptime, a HID, etc. and put them as seed into an algorithm like the Mersenne Twister to receive a random number. The downside is, that given the same environment, one can re-calculate the random number. Since it is re-calculable, it only can be used for low-security applications (for example randomness in computer games).

True random numbers usually can be used for cryptography, hence are very interesting for a wide number of applications, like secure banking transactions, transmission of secrets (e.g. military).

In order to create a true random number, one usually takes a constantly, rapidly changing outside phenomenon translates it into a number, and inserts it into a formula. Such an outside phenomenon can be radio waves, radiation, atmospheric noise, chaotic lasers, etc. They usually require additional hardware sensors, however generate a number, which is hard (ideally impossible) to reconstruct, guess or intercept in any way.


Summary: In order to easily get a low-quality random number, you can use something like the current ns, slice them like a string and only take the last few digits. In order to get a medium quality random number, you might want to take a number from /dev/random, which includes pre-calculated random numbers with a "good" algorithm. For high-quality random numbers, you will need extra hardware, which provides a value from a physical phenomenon, which cannot be reconstructed.