php - Asking for advice on the algorithm for distributing materials
PHPz
PHPz 2017-05-24 11:33:26
0
2
1217

Now there is an activity to get materials for answering questions, a total of three days
4 kinds of materials 1, 2, 3, 4. Material 4 is a scarce material.
If the question is answered correctly, a material will be distributed to the player. Material 4 will not appear on the first day, and no more than 50 copies of material 4 will appear on the second day. By the end of the event, no more than 200 copies of material 4 will appear (because the winning list must be limited to Within 200 people)
Players who get material 4 need to have collected 1, 2, and 3 before so that they can win the prize
How should the algorithm for allocating materials be best written?

PHPz
PHPz

学习是最好的投资!

reply all(2)
淡淡烟草味

This is nothing more than Jingyefu’s way of playing. 123 can be given as you like, there is no need to limit the quantity, just control the quantity of 4. On the first day, there were 3 prizes, and in the next two days, there were 4 prizes. In the lottery, draw 4 to determine whether it exceeds the limit for the day. If it exceeds, just randomly return one of 1, 2, and 3.

漂亮男人

Although I have never done anything like this, I can express my personal thoughts
Since you cannot determine the number of users in the lottery and the data of each material (non-material four)
The second pair of material four is displayed, and it does not appear on the first day. No more than 50 on the second day, no more than 200 at the end of the event
So the probability of material four is separated from materials 1, 2, and 3, that is, the probability of material four is calculated. If not, calculate 1, 2, 3 (directly use random numbers It’s ok)

The variables include
the total number of materials four, activity start time, end time, current time, the number of materials four displayed on the second day, and the extracted code

Code
Judge whether it is the first day
Yes, the probability of material four is 0, randomly assign 123
No, judge whether it is the second day
Yes, judge whether the total number of material four drawn exceeds 50, if yes, directly randomly assign 123, if not, calculate the probability of material four The probability of material four can be based on the remaining total number of material four as the numerator and the current total number of draws as the denominator. Of course, in order to prevent the denominator from being too low, a minimum value should be set. If material four cannot be calculated, the randomly allocated material 123
does not satisfy the The first or second day is the third day. The calculation logic is similar to the calculation of the second day

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template