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
Although there are many factors that affect the c...
As mentioned in previous articles, design compone...
"iOS8.1 already has this feature, but it was...
PDCA stands for Plan, Do, Check, and Action, whic...
According to official measurements by the China E...
Here, I would like to talk further about how to b...
We can observe from the WeChat platform that it n...
Fast radio bursts (FRBs) are a type of supernorma...
Produced by: Science Popularization China Author:...
[[146697]] Swift provides a high-performance, Uni...
Recently, Fenda has become very popular on WeChat...
Recently, Microsoft introduced and provided a pre...
Friends who are interested, please think back, in...
Review expert: Peng Guoqiu, deputy chief physicia...