The first thing I should say is that probably there is a name for this kind of problem, I simply don't know its name.
The explanation:
There is 8 ball slots and 100 balls to be randomly distributed between the slots. There are 3 different types of slots: red, green and blue. The red slot type must have at least 6 balls total, the green 15 and the blue doesn't matter.
Besides the needed amount for each different colors, there is the possibility of having multiple red, green or blue slots, each one comes with the same rate of the balls that shall go into them. Red is 4%, Green is 15% and Blue is the rest that wasn't picked.
So randomly suggesting a sequence this is a possibility:
Slot 1 - Blue with 17 balls
Slot 2 - Green with 8 balls
Slot 3 - Green with 12 balls
Slot 4 - Red with 1 ball
Slot 5 - Blue with 33 balls
Slot 6 - Red with 7 balls
Slot 7 - Blue with 12 balls
Slot 8 - Green with 10 balls
Note that the required amounts have been filled, and also there is more than one Red and Green slots, although its only needed one (with at least that total amount of balls inside).
What I need is a pseudo-code or a code in any language showing how to distribute all the 100 balls between different slots and with different weights. I have been programming it but every 3 runs, one fails to distribute every single ball, it misses some.
Aucun commentaire:
Enregistrer un commentaire