Fighting one's luck to grab red envelopes has long been a regular part of the Spring Festival holiday. For many people, the amount is not important, as the whole point is to bring excitement and celebration. However, in the same red envelope, why do some people get a "huge sum" while others only get a few cents? Are there any rules for winning lucky red envelopes? Is there really a difference between grabbing first and grabbing last?
Today, CCTV News "Quanshi Hard Technology" revealed the algorithm behind grabbing red envelopes.
Initially, red envelopes used a completely random distribution logic - the total amount and number of people were fixed and randomly distributed by the system., it seems to be all about luck, but there are obvious loopholes in this method: the earlier you grab it, the higher the probability of getting a large red envelope in theory.


For example, if 100 yuan is distributed to 10 people, the amount that the first person can grab may range from 0.01 yuan to 100 yuan.
If he only grabs 10 yuan and leaves 90 yuan for the next person, the second person's allocation range becomes 0.01 yuan to 90 yuan, and the expected value drops to 45 yuan.
As the number of people decreases and the amount of money shrinks, the expectations of those who grab the money will continue to decline, which is obviously unfair.
In order to solve this problem and take into account fairness while retaining randomness, the platform introduced the double mean method, which is known as the golden rule in the red envelope world.
The core idea is:Set an upper limit for the amount of money for each user, at least 0.01 yuan, and no more than twice the average remaining amount.

Still taking 100 yuan distributed to 10 people as an example, the first person can only grab 100÷10×2=20 yuan at most, and the amount range is 0.01 yuan to 20 yuan. The mathematical expectation is about 10 yuan, not 50 yuan.
If he only grabs 1 yuan, and the remaining 99 yuan is divided among 9 people, the upper limit of the second person is 99÷9×2=22 yuan, and the expected value is about 11 yuan;Even if the first person directly grabs the upper limit of 20 yuan, and the remaining 80 yuan is divided among 9 people, and the second person's upper limit is 80÷9×2≈17.78 yuan, the expected value still remains at around 8.89 yuan.
It can be seen that by dynamically adjusting the upper limit, the expected value of each participant always fluctuates around the average value, which not only retains the random fun, but also avoids grabbing advantages first and suffering big losses later.
Of course, the real algorithm for grabbing red envelopes is more complicated. In addition to ensuring a relatively fair distribution of amounts, the platform must also take into account various details such as minimum amount limits and system stability under high concurrency.