Java implements a simple red envelope grabbing algorithm (simulating real red envelope grabbing)

I have nothing to do. Recently, the project needs to write the user login home page to send a cash red envelope. There is no limit. I calculated a little by myself. If there is a limit, how should I write it. I think this is similar to wechat red envelopes. After the project requirements are completed. Just come to the blog and post my own red envelope removal algorithm. Personally, I think this algorithm simulates the real red envelope rule. Cut the crap. Paste the code first;

The thinking logic of this Code:

1. First of all, we should divide the red envelope amount into N parts according to the number of people, but because of the average value. If everyone is too evenly divided, it will appear that it is not playable.

2. Secondly, how should we divide? To ensure that the red envelope has strong playability. In fact, I don't think these are important. After all, red envelopes only depend on luck. I was unlucky to play wechat red envelopes. I also drew 0.01 yuan for 3 people. Concurrency will also be large. So my code simply puts everyone's random number (the range of random number is number * 100), adds the random numbers of these people together, and then calculates the percentage of each person's random number. Divide the red envelope according to this percentage.

The above is the Java implementation of the simple red envelope grabbing algorithm (simulating the real red envelope grabbing) introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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
分享
二维码
< <上一篇
下一篇>>