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
I joined LinkedIn in 2011, and since then I have ...
Part of human history lies in the seabed corals, ...
Recently, Qionghai, Hainan A grass fire After rec...
For many webmasters and enterprises, before the h...
iPhone 6s, as Apple's blockbuster product, wi...
Recently, the National Development and Reform Com...
"Are you messing with me again? I remember t...
Love is a universal and abstract emotion of human...
[[153454]] 1. Apple uses products such as iPhone,...
As winter arrives, it’s time for the north to rel...
The United Nations Educational, Scientific and Cu...
Shenzhou 13 "Space Trio" In orbit for m...
Fang Dahai's five acupoints basics and applic...
What are the promotion and operation skills of Pi...
The course comes from Mr. Krabs’s medium-length vi...