Over the weekend, I went to the cinema with my girlfriend to see Avengers: Endgame. As a Marvel fan, three hours of watching was more than enough. When I get out, I’m going to talk to my girlfriend about 10 years of Marvel.

In the Avengers movies, Thanos’s lifelong goal is to maintain the balance of the universe by erasing half of all life.

And, according to Thanos, the process is “random, impersonal, absolutely fair, no matter how high or low.”

So, what exactly is random? Is his randomness really as impersonal, utterly fair, and free of distinction as he claims?

randomness

Randomness is a word used to express a lack of predictability in purpose, motivation, rules, or some non-scientific use. A random process is a repeated process in which indefinite factors are produced.

When it comes to randomness, random number has to be mentioned. Random number is widely used in computer applications, and is most known for its application in fields such as communication security and modern cryptography.

Random number is divided into true random number and pseudorandom number, we use the basic pseudorandom number.

  • Truly random numbers, obtained by physical experiments, such as coin rolling, dice, wheel spinning, electronic noise, nuclear fission, etc. Randomness, unpredictability, and unrepeatability need to be satisfied.

  • Pseudo random number, through a certain algorithm and seed. The software implements pseudo-random numbers.

As long as the random number is generated by a deterministic algorithm, it is pseudorandom. Only through constant algorithm optimization, make your random number more close to random.

Finite state machines cannot generate truly random numbers. Therefore, modern computers cannot generate truly random numbers through a pure algorithm. In either language, the numbers generated by pure algorithms are pseudorandom numbers, pseudorandom numbers generated by determinable functions through a seed.

Why is Thanos unfair?

As mentioned earlier, truly random numbers should meet the requirements of randomness, unpredictability and unrepeatability.

Let’s take each of these properties and see if Thanos is fair.

randomness

Randomness, meaning the absence of statistical bias, is a completely chaotic sequence of numbers.

After Thanos’s finger tap in Infinity War iii, the list of Avengers who live and die isn’t actually random. Many of these CP pairs kill one and leave one. Such as Iron Man – Spider-Man, Captain America – Winter Soldier, Rocket Raccoon – Groot, Ant-Man – Wasp woman and so on.

Also, there is a chance that Thanos himself will be erased if it is random, but he already knows he won’t be erased and has already made a retirement plan.

Also, in Avengers 3, Doctor Strange swapped iron Man’s life for the Time Stone and Thanos, suggesting that Thanos was selectively erased.

Thus, Thanos’s finger wiping process is not random.

unpredictability

Unpredictability refers to the inability to predict the next number from a past sequence.

Those of you who know the movie know that Doctor Strange used the Time Stone to travel through time and predict the future and saw 14000605 possibilities.

Thus, Thanos’s finger wiping process is not unpredictable.

unrepeatability

Non-reproducibility, the inability to reproduce the same sequence unless the sequence itself is saved.

In Avengers 3, Iron Man asks Doctor Strange how many of the 14000605 possibilities he can win. Strange replied: 1.

At the end of Avengers 4, Doctor Strange gives iron Man the following gesture. It meant that the only possibility of victory he had ever seen was about to recur.

Thus, Thanos’s finger wiping process is not impossible to reproduce.

To sum up, Thanos’ finger-erase process does not conform to randomness, unpredictability and irretrievability. So, Thanos’s finger-wiping process isn’t really random.

Judging by the appearance, It is likely that Thanos’s erase operation was achieved through simple stratified sampling. The simple operation process is as follows:

  • 1. The DNA of people requiring special treatment without erasure is separately identified from the DNA bank of all species and stored in the cache.

  • 2. According to different conditions, all living organisms in the DNA bank are divided into several blocks, such as Earthmen and Asgardians. Keep their DNA information in different databases. During traversal, if it encounters data already in the cache, it skips.

  • 3. According to species diversity, such as gender, age, occupation, etc., the data in the same sub-database are divided into different tables to ensure that each sub-table contains complete species diversity.

  • 4. Iterate over all databases and delete half of the tables in each database in order. For example, there are 1024 tables in the database of earth people, only 512 can be reserved.

  • 5. Synchronize the cached data to the database.

That way, when you need to resurrect these people later, you just need to find the database’s Binlog and write the data back to the database.

True random number generator

Truly random numbers are generated using physical phenomena rather than computer programs. The device for generating random numbers is called a true random number generator.

Such devices are usually based on microscopic phenomena such as thermodynamic noise, photoelectric effects and quantum phenomena that generate low-grade, statistically random “noise” signals.

To some extent, a random number chip based on classical thermal noise reads the noise in the current physical environment and obtains random numbers accordingly. Such devices are harder to predict than software-based implementations because there are more variables in the environment.

However, under the framework of Newtonian mechanics, even though there are many variables that affect the generation of random numbers, the operation state and output of the whole system can be predicted in principle after the initial state of each variable is determined. Therefore, this kind of device is also based on a deterministic process, which is just a pseudo-random number that is more difficult to predict.

However, the discovery of quantum mechanics fundamentally changed this situation, because its basic physical processes have intrinsic randomness, which is not found in classical physics, and thus can produce true random number generators.

According to the website of the National Institute of Standards and Technology (NIST), researchers reported in the April 2018 issue of the journal Nature that they have developed a new method for generating random numbers guaranteed by quantum mechanics. The new technology is helping to make cryptography systems more secure by surpassing all previous methods of obtaining “truly random numbers”. (the original address: https://www.nature.com/articles/s41586-018-0019-0.epdf)

NIST mathematician Peter Bilhorst further explained, “Situations like flipping coins seem random, but if you can see the exact path of the coin, the end result is predictable. Therefore, it is difficult to guarantee that a given classical source is truly unpredictable. Quantum mechanics is better at generating randomness, which is truly randomness, because measurements of quantum particles in a ‘superposition’ state yield results that are essentially unpredictable.”

In Avengers 4, there is also a lot of knowledge about quantum physics, and even the ultimate game-changer is the quantum realm. The tenet of Marvel movies can be summed up in four broad phrases: “When things get tough, quantum mechanics.” It doesn’t make sense. Through time. Not enough space, parallel universes. The law is insufficient, high dimensional Terran.

Random number generator in Java

Generating random numbers in Java is relatively easy, and Java provides a variety of apis for developers to use.

Acquisition by time

In Java, we can get the current time in milliseconds with System.CurrentTimemillis () :

final long l = System.currentTimeMillis();
Copy the code

To obtain a specified range of numbers, just modulo the numbers. The following method can obtain random numbers from 0 to 99:

final long l = System.currentTimeMillis();
final int i = (int)( l % 100 );
Copy the code

Math.random()

Math.random() returns a double between 0(included) and 1(not included). The usage method is as follows:

final double d = Math.random();
Copy the code

To get an integer of type int, simply cast the result to type int. For example, get an int between [0, 100].

final double d = Math.random();
final int i = (int)(d*100);
Copy the code

The Random class

Java provides the pseudo Random number generator with Java. Util. The Random class and Java. Util. Concurrent. ThreadLocalRandom class.

The Random class adopts AtomicLong to ensure the thread safety of multiple threads. However, as explained in the class annotation, the performance of concurrent Random number acquisition by multiple threads is poor.

ThreadLocalRandom can be used as a random number generator in multi-threaded environments. ThreadLocalRandom uses thread-local variables to improve performance, so long can be used instead of AtomicLong. ThreadLocalRandom is also byte populated to avoid pseudo-sharing.

If Random is used to obtain an int integer between [0, 100], the method is as follows:

Random random = new Random();
int i2 = random.nextInt(100);
Copy the code

Strong random number generator

Strong random number generators rely on random events provided by the underlying operating system. Strong random number generators are slow to initialize and generate, and may cause blocking due to the entropy accumulation required to generate sufficiently strong random numbers. Entropy accumulation usually comes from multiple sources of random events, such as the time interval between keystrokes, the distance and interval between mouse movements, and the time interval between specific interruptions. Therefore, use it only when you need to generate highly encrypted random data.

Java provides strong random number generator is Java. Security. SecureRandom class, the class is a thread-safe class, use the synchronize method to ensure the safety of the thread, but the JDK is not promised change SecureRandom thread safety in the future. Therefore, as with Random, performance problems may occur in a highly concurrent multi-threaded environment.

This pot, r & D personnel do not carry!!

According to my guess. For the infinite glove product, the initial demand of the product manager may only be to satisfy the user’s wish, while a few gems are just like the seven dragon balls, which can be realized by clicking their fingers after collecting them.

The developer simply provides a desired API, with a Callback as the argument, and what it does is entirely up to the user to pass in the idea. It’s like Thanos trying to erase half of life, Hulk trying to bring back the people who were erased, and Iron Man just trying to erase the bad guys.

And finally, Tony, Love You 3000 Times.

References:

https://www.cnblogs.com/skywang12345/p/3341423.html

https://www.zhihu.com/question/277121161 http://www.nsfc.gov.cn/csc/20340/20343/30636/index.html

http://sh.people.com.cn/n2/2018/0413/c134768-31460133.html