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
“Number theory provides us with an inexhaustible ...
Expert of this article: Liu Yadan, former assista...
[[204795]] sequence Using custom fonts on Android...
The Pegasus program began in the spring of 1987 a...
When it comes to Dyson, the first thing that come...
After the beginning of spring, the weather is gra...
Expert of this article: Fu Shufang, Master of Foo...
You must have seen headlines like this: "Oh ...
When talking about a product, people often use use...
With the rapid development of Bilibili, both ente...
A Boston company called Rehtom once posted a very...
After completing the basic steps of on-site optim...
The development of the Internet has entered the s...
Even those who are just starting out in operation...
Scientists are intrigued by the fact that we can ...