Pergunta

I am developing small lottery games where the participant can win one of many gifts, each having various quantities. (The code is in PHP)

Simple scenario:

I have 5 types of gifts, 1000 in total, and am expecting 1000 participations. What algorithm can I use to ensure that these 1000 gifts are distributed somewhat evenly. The time period doesn't matter.

Uneven: 2 drones given away first, then 10 tablets, etc...

| Title     | Quantity |
|-----------|----------|
| Drone     | 5        |
| Tablet    | 10       |
| Hotel     | 100      |
| Gift card | 200      |
| Coupon    | 685      |

More complex scenario:

I have the same gifts and gift quantities, but I anticipate 600 participations. I wish for the drone, tablet, and hotel nights to be all given out by the 600th participation.
So there should be 400 (gift cards + coupons) left, and better if there's the same percentage left: 116 gift cards (200/685=29%) and 284 coupons (71%).

What I tried:

For the first scenario, I tried using these probabilities, and looping through the 5 gifts sequentially:
- Each gift has its own counter
- The gift's counter increases every time the gift is considered
- The gift is given if the gift's counter == originalQuantity
- The loop starts back from the drone when a gift is given

| Title     | Quantity | Probability                   |
|-----------|----------|-------------------------------|
| Drone     | 5        | 5/1000                        |
| Tablet    | 10       | 10/(1000-5)                   |
| Hotel     | 100      | 100/(1000-5-10)               |
| Gift card | 200      | 200/(1000-5-10-100)           |
| Coupon    | 685      | 685/(1000-5-10-100-200) = 1/1 |

This solution works, and by adding a coefficient to each gift (Drone, table and hotel must have 20% more chance to come out, and gift card and coupon 30% less chance), I could also handle the more complex scenario.

My question is: are there better, fairer, simpler ways to distribute these gifts ?

Edit 1: Even distribution would mean random, and have for example, after 20% of participation, have approximately 20% of each gifts given out (1 drone, 2 tablets, etc...)

Foi útil?

Solução

You can just do it like the lottery: shuffle and pick. It is possible that the same kind of item is picked two or more times, just as it is possible that sequential rolls with dice yield the same number, that's how random works :-)

For the case where a number of prizes should be drawn until the 600th draw, put all of these prizes in a list together with enough of the other prizes to make 600, then shuffle that list. Shuffle the remaining 400 and concatenate the shuffled lists.

Licenciado em: CC-BY-SA com atribuição
scroll top