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
What efforts have you made to become thinner and ...
Android phones are updated so quickly that every ...
News on July 23, starting today, the 2020 college...
With the popularity of Douyin live streaming and ...
The Chinese New Year is coming soon, and WeChat a...
Source code introduction: An iOS gesture password...
Preface How can you make users addicted to your p...
The world of unicorns is never short of stories. ...
On the one hand, the professionalism of “If you h...
This blog post is from 51CTO blogger jxw167. If y...
Cui Dongshu, secretary general of the China Passe...
How does a novice sell goods through live streami...
In the film and television industry, we often hea...
Private Domain Traffic Practical Training Camp In...
On March 23, after review by the National Medical...