# Efficient and fair way to evenly distribute multiple items with various quantities

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 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...)

• You should make a better definition of "evenly distributed". Do you mean that the same gift does not appear in a row? Or what Is the criteria? Must it be random or can it be deterministic? Feb 17, 2020 at 20:31
• Not sure I understand the question. Your algorithm can hand out gifts in any order you like, for example determine winner for one drone, then one tablet ... I think you need to better define "even" and "fair". Feb 17, 2020 at 21:38