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 rise of short videos has brought countless ne...
The world we live in is full of mysteries. Perhap...
With the rise of various major accounts, the new ...
Review expert: Yin Tielun, deputy chief physician...
On July 17, Baidu Apollo Robotaxi was officially ...
Recently, according to Russian media reports, the...
CPD Promotion Platform Introduction The vivo App ...
The 56th lecture of Quantitative Science by Jiang...
The ideal of many Internet newcomers is how to re...
In fact, everyone has read a lot of useful inform...
As the mobile phone market matures, more and more...
Many conspiracy theories start like this: as long...
At present, emerging brands are developing at an ...
You must have heard of ChaCha Foods. Yes, the Cha...
A few days ago, I went shopping with a friend who...