The Problem with Random Numbers

  sonic0002        2024-06-21 21:09:14       2,138        0    

Today, let's talk about how to generate true random numbers. This is an extremely difficult problem, but it involves some very interesting content.

First of all, the random numbers provided by programming languages are pseudo-random numbers. 

The V8 engine’s official website has an article that particularly reminds everyone of this point. The built-in random numbers are not true random numbers but pseudo-random numbers.

Math.random() returns a Number value with positive sign, greater than or equal to 0 but less than 1, chosen randomly or pseudo-randomly with approximately uniform distribution over that range, using an implementation-dependent algorithm or strategy. This function takes no arguments.

Pseudo-random numbers are not truly random but are derived from an algorithm. As long as the initial seed value is the same, the algorithm will yield the same result. JavaScript and many other languages have this issue. Therefore, in scenarios where randomness is especially emphasized, the built-in random number generators should not be used.

True random numbers need to meet three conditions:

1. Unpredictability: Random numbers cannot be guessed, so they must be very large to avoid brute-force attacks.

2. Non-repetition: Each generated random number should be unique.

3. Uniform Distribution: Random numbers must be evenly distributed across all intervals and not concentrated in certain areas.

Generally speaking, true random numbers can only be obtained through hardware; pure software algorithms cannot achieve this. Scientists have racked their brains to come up with various methods to generate random numbers through hardware.

The famous Random.org is a website specifically designed to generate random numbers. 

It has deployed multiple radio receivers around the world to listen to atmospheric radio waves (i.e., atmospheric noise, which can be understood as Brownian motion in the atmosphere) and generates random numbers through these random radio signals. Below is an image of its early hardware equipment.

Because of the hardware costs, using its random numbers requires a fee. So, as you can see, true random numbers come with a cost; it's not just a matter of running a program.

The world’s largest CDN service provider, Cloudflare, goes even further to obtain true random numbers. Each of its three offices has different random number generation devices.

San Francisco Headquarters: There is a wall full of lava lamps right at the entrance.

The melted wax inside the lava lamps constantly changes shape. When a random number is needed, a photo is taken of this wall. Each photo is different, and then the hash of the photo is calculated and used as a seed value to compute a random number.

London Office: There is a "pendulum wall" filled with various pendulum devices.

The pendulums and their shadows are constantly moving. The hash of each photo is also different and can be used as a seed value for random numbers.

Austin Office: The ceiling is covered with many colorful reflectors.

These reflectors are very sensitive to air flow; opening or closing a door, air conditioning, temperature, and humidity all cause them to move and reflect different colors of light. Therefore, they can also be used as seed values for random numbers.

Reference: https://www.ruanyifeng.com/blog/2024/06/weekly-issue-305.html

HISTORY  RANDOM NUMBER  TRUE RANDOM  PSEUDO RANDOM 

       

  RELATED


  0 COMMENT


No comment for this article.



  RANDOM FUN

What should be the right code indentation