I need to generate a set o random numbers that will be used to distribute some objects in containers.
All containers can store up to 5 objects except for one, that can store up to 14 objects.
I have 25 containers and 70 objects.
What I'm doing now is generating 25 random numbers between 0 and 14. Then I sum all of them to normalize the initial set, dividing each number by the sum.
So now I have a set of numbers that represents the proportion of objects in each container.
To get the number of objects for each container I multiply the proportion by 70, but here I get a problem. The proportions are all floating point numbers, and I can only store an entire object on each container.
If I round the numbers some numbers are rounded up, and some down. Then when I sum all objects I can get anything between more or less 65~75. But I need to distribute exactly the 70 objects.
Does anyone have an ideia on how to fix it?
Or any other ideas on how to solve this?
I don't necessarily need to follow this approach, I can use any method to transform the initial random set into the distribution. My requirements are only that:
- the initial set of data must be random integer numbers (any quantity or range)
- given two identical initial sets, the distribution of the objects into the containers must be the same