I saw a question on Zhihu: How is the random algorithm for WeChat red envelopes implemented?
Some people say that Tencent achieved this roughly like this:
Some people have also done normal distribution, variance analysis, regression analysis, statistical simulation, etc., but I won’t post it because the picture is too long. However
Let’s change our thinking. Now we change all the money into 1-cent coins, imagine the red envelope as a jar, and then scatter the coins.
Red envelopes are randomly selected for every penny. As for regression analysis and statistical simulation, they are of no use at all. In this example, we abandon traditional concepts such as "drawing" and "random amount", so that money has a sense of choice and performs "random" behavior. Naturally, the red envelope has the attribute of random amount. Change your thinking and don't complicate simple problems. When we design code, we usually consider the logic in real life and abstract objects into classes and behaviors into methods. However, we also need to consider the reversal of thinking occasionally. Of course, my code has certain drawbacks. Thinking is the most important thing. |
<<: Xiaomi Mi A1 releases kernel source code: turns into the little prince of flashing
The launching ceremony of China's third aircr...
Produced by: Science Popularization China Author:...
Today I bring you the latest traffic rankings of ...
How was the Moon formed? The most mainstream hypo...
Introduction I once used a canvas belt for six ye...
Produced by: Science Popularization China Author:...
Recently, Yun OS has been the hottest topic in th...
Abstract: Children's Day is approaching. Inst...
Course Description: The official product of the O...
At 8:11 a.m. on December 10, the Long March 4B ca...
Mobile phones emit radio waves, and whether the u...
2020 is also known as the "first year of the...
Take a cosmic journey with the world's larges...
What time do you usually have breakfast every day...
Uncle Nan's Night Reading Short Video Book Se...