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
◎ Science and Technology Daily reporter Zhang Ye ...
Twenty years ago, Jim Hall, an undergraduate physi...
In 2020, Evergrande Group officially announced it...
There is a process for consumers to come into con...
From 0:00 to 24:00 on May 2, 31 provinces (autono...
Let's go to the Red Planet, a live streaming ...
Let's do a multiple-choice question first. Wh...
[[265644]] According to the 21st Century Business...
We have been dealing with paper for many years an...
Introduction: It has to be said that the topic of...
recently A topic became a hot search It sparked h...
Birth, aging, illness and death are the most natu...
According to foreign media reports, Apple CEO Tim...
How will my promotional information be displayed?...
How can event posters and poster copy achieve hig...