In today's world, computers are indispensable in every field, from aerospace engineering to information management, from artificial intelligence to process control. But computers are not omnipotent. There are many things that they cannot do, even some seemingly simple things, such as generating random numbers. Can't computers generate random numbers? Many activities, such as the company's annual meeting lottery, are not all conducted by computer lottery? Indeed, computers can generate random numbers, but the random numbers generated by computers should be put in quotation marks because they are not real random numbers, but "pseudo-random numbers". Why can computers only generate pseudo-random numbers? Because computers don't roll dice. Rolling dice is a very simple thing for a person, but it is extremely difficult for a computer, because all the actions of a computer must have a specific program, and the generation of random numbers is no exception. What is a random number? Simply put, the appearance of a number does not follow any rules. The appearance of the first number cannot determine the second number. Similarly, the third number has nothing to do with the first two numbers. This is impossible for a computer. Computers can make the generation process of "pseudo-random numbers" more complicated by improving the algorithm, but this still cannot change the nature of "pseudo-random numbers". So how do computers generate "pseudo-random numbers"? The earliest pseudo-random number generation method was developed by John von Neumann, the father of computer science. It is called the "square middle method". Now this random number generation method has been completely abandoned. The so-called square middle method first requires a seed number to be selected. This number is set in advance and can be 1234 or 5678. Let's take 5678 as an example. The first step is to square the seed number. 5678 multiplied by 5678 equals 32239684. After completing the first step of squaring, the next step is to find the middle. The so-called middle method is to take the middle four numbers of 32239684, that is, remove the 32 in front and the 84 in the back, and the remaining four numbers in the middle are 2396, which is the first random number. The second random number is to repeat the calculation process of squaring the first random number, that is, 2396 multiplied by 2396 equals 05740816, and the four numbers in the middle are 7408, which is the second random number. Since the square middle method is too simple, as long as you know the seed number, you can calculate all the subsequent random numbers, so it is no longer used. Another relatively simple but still used method of random number generation is called the "congruential method". The congruence method first requires two constants, for example, the first constant is 444 and the second constant is 1234. Now we still need to have a seed number, let's take 5678 as an example. The first step is to multiply the seed by the first constant, that is, 5678 multiplied by 444 equals 2521032. The second step is to divide the result of the first step by the second constant, that is, 2521032 divided by 1234, which is rounded to 2043, which is the first random number. The second random number is generated by repeating the above steps with the first random number, 2043 multiplied by 444, and then divided by 1234, which equals 735, which is the second random number. Compared with the square median method, the congruence method is much more complicated. Not only do you need to know the seed number, but you also need to know two constants in order to calculate all the random numbers that appear later. Of course, if you know in advance what kind of program is used and have enough random number samples, you can also calculate the constant. However, the congruential method can be transformed, such as adding an addition after the multiplication, and then adding a third constant, which becomes the "linear congruential method", which is more complicated. Both the congruential method and the square middle method are relatively simple random number generation methods, and the random number generation method we mainly use now is the much more complicated "Mersenne rotation algorithm". This algorithm involves a relatively complex calculation process and involves the mathematical knowledge of matrices and vectors. The random number distribution generated by this method is very close to true random numbers, but it is still a pseudo-random number in essence, and there is a logical relationship between each number. For more information, please follow the official account: sunmonarch |
<<: If the earth stops rotating, where will the fish in the rivers, lakes and seas go?
>>: What happens when you flush the toilet?
For Apple developers, we have entered the "Sw...
Image quality is an unchanging requirement for di...
Developing an APP is actually not difficult. The ...
As the weather turns cooler, it is time to prepar...
A freshwater lake that was originally 3 meters de...
Since March, more than 270,000 cases of local inf...
Apple held its 2019 spring conference again, and ...
In Internet advertising, paid-per-click advertisi...
When it comes to the general price of wedding san...
How much does it cost to develop the Huaihua Elec...
introduce TabBarView implements the category menu...
[[136289]] As you can see, there are already over...
At the 9th Internet Audiovisual Conference, "...
This morning South China National Botanical Garde...
What would you do if you found out that your room...