Red Envelopes tell you that learning mathematics well can really grab more red packets !! Next, I will share with you the secret of snatching red packets. In a simple summary, let your friends first! The red packet distribution algorithm code is implemented and sent to everyone!
# Coding = gbkimport randomimport sys # print random. randint (0, 99) # print "=", random. uniform (0, 0.99) def calRandomValue (min, max, total, num): print min, max, total, numtotal = float (total) num = int (num) min = 0.01if (num returnif num = 1: print "% d: %. 2f "% (num, total) returni = 1total_money = total # rtotal = (total * 100-min * num * 100) /100 while (I max = total_money-min * (num-I) k = int (num-I)/2) if num-I k = num-imax = max/kmonney = random. randint (int (min * 100), int (max * 100) monney = float (monney)/100total_money = total_money-monneyprint "% d the number of red packets received by individuals is %. 2f, balance: %. 2f "% (I, monney, total_money) I + = 1 print" % d: %. 2f, balance: %. 2f "% (I, total_money, 0.0) if _ name _ =" _ main _ ": min = sys. argv [1] max = sys. argv [2] total = sys. argv [3] num = sys. argv [4] calRandomValue (min, max, total, num)
Python 2.py 0.01 10 20 30
0.01 10 20 30
1st people receive 1.34 red packets, with a balance of 18.66
2nd people receive 1.06 red packets, with a balance of 17.60
3rd people receive 1.08 red packets, with a balance of 16.52
4th people receive 0.98 red packets, with a balance of 15.54
5th people receive 0.88 red packets, with a balance of 14.66
6th people receive 0.48 red packets, with a balance of 14.18
7th people receive 0.26 red packets, with a balance of 13.92
8th people receive 0.90 Red Packets, with a balance of 13.02
9th people receive 0.12 red packets, with a balance of 12.90
10th people receive 0.41 red packets, with a balance of 12.49
11th people receive 0.43 red packets, with a balance of 12.06
12th people receive 0.63 red packets, with a balance of 11.43
13th people receive 0.36 red packets, with a balance of 11.07
14th people receive 0.25 red packets, with a balance of 10.82
15th people receive 1.38 red packets, with a balance of 9.44
16th people receive 0.17 red packets, with a balance of 9.27
17th people receive 0.79 red packets, with a balance of 8.48
18th people receive 0.52 red packets, with a balance of 7.96
19th people receive 0.44 red packets, with a balance of 7.52
20th people receive 1.15 red packets, with a balance of 6.37
21st people receive 0.13 red packets, with a balance of 6.24
22nd people receive 0.76 red packets, with a balance of 5.48
23rd people receive 1.32 red packets, with a balance of 4.16
24th people receive 0.80 red packets, with a balance of 3.36
25th people receive 0.16 red packets, with a balance of 3.20
26th people receive 0.27 red packets, with a balance of 2.93
27th people receive 1.82 red packets, with a balance of 1.11
28th people receive 0.45 red packets, with a balance of 0.66
29th people receive 0.27 red packets, with a balance of 0.39
30th people receive 0.39 red packets, with a balance of 0.00
The above is all the content of this article. I hope you will like it.