Java wechat random red envelope algorithm code example

One night a few days ago, I suddenly thought that there should be a random algorithm for wechat red envelopes. I tried to write it myself. I don't know if it's right. After reading the online statement, it seems that the official hasn't given an exact algorithm so I have to make a fool of myself here and post the code first:

The basic idea here is as follows: first, calculate the average value of the red envelope, and then use a red envelope whose random number of red envelopes is less than the average value. When the red envelope is sent, the total amount of the red envelope needs to be reduced accordingly. At the same time, recalculate the average value: the new total amount% (the original total number of red envelopes - 1), until the last red envelope, insert all the remaining amounts.

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>