<p><em>Given n items (20% type A, 80% type B), I'm looking for a way to distribute them randomly into g groups of equal size.</em></p>

<p>To a statistician there is an unambiguous meaning to this statement.  Which is to take <code>n</code> items, mark 20% of them as being of type A, shuffle them, then pull off groups of size <code>n/g</code>.  For large <code>n</code> the resulting distribution will be very close to the binomial one.  But it won't exactly be the binomial distribution.  In fact there is a persistent bias towards being even more even than the binomial distribution, because when one thing of type A goes into a group it fills the group up a bit and makes it less likely that the next thing will go into that group.</p>

<p>It is straightforward to write code to create a list of things, perform a shuffle, and then pull out the groups.  This will run in time <code>O(n)</code>.</p>

CC BY-SA 3.0
2011-07-19T04:42:45.933Z
2011-07-19T04:42:45.933Z
btilly
<p>Given n items (20% type A, 80% type B), I'm looking for a way to distribute them randomly into g groups of equal size. It must be possible for one group to end up with As in the majority but it must not be inevitable. I.e. If I was using binomial distribution, it would be extremely unlikely (with large values of n) to get a group in which the proportion of As was far from 20%. With uniform distribution between 0 and n/g, the first group to which As were allocated would almost always get many more As than the other groups (because the mean of the distribution function would be 50% rather than 20%). </p>

<p>I don't know much about stats and probability so this may be a stupid question but I suppose what I am asking for is a distribution function whose mean is 0.2 but which is likely to generate numbers between 0 and 0.2 and numbers between 0.2 and 1 with equal probability as well.</p>

CC BY-SA 3.0
2011-07-18T19:13:19.190Z
I do not know what you mean.  Why doesn’t the uniform distribution on [0,0.4] satisfy your condition in the second paragraph?
Tsuyoshi Ito
CC BY-SA 3.0
2011-07-18T19:58:00.857Z
I need it to generate 1 with some non-zero probability too. Uniform over [0,0.4] will never give you anything more than 0.4 right?
Nick
CC BY-SA 3.0
2011-07-18T20:49:27.637Z
By your own constraints, you're requiring 0.2 to be the mean and the median of the distribution. One way to achieve this is to place a uniform distribution on [0,0.2] and construct a (probably exponential) distribution on [0.2,1] whose mean is at 0.3. Taking the average of these distributions will yield what you want.
Suresh Venkat
CC BY-SA 3.0
2011-07-18T21:17:25.190Z
“I need it to generate 1 with some non-zero probability too.”  Where did you state that requirement?
Tsuyoshi Ito
CC BY-SA 3.0
2011-07-18T21:34:58.147Z
I feel that "it must be possible for one group to end up with As in the majority" and "numbers between 0.2 and 1" suggest it. Maybe not :D.
Nick
CC BY-SA 3.0
2011-07-19T03:01:18.443Z
I feel that this question might be better suited for: http://stats.stackexchange.com/
Artem Kaznatcheev
CC BY-SA 3.0
2011-07-19T18:29:17.127Z
I don't understand the question, but, just as a long shot, are you looking for something like the [multinomial distribution](http://en.wikipedia.org/wiki/Multinomial_distribution)?  It generalizes the binomial distribution so that you can partition into more than two sets.
James King
<pr.probability><st.statistics>
Distributing items randomly into groups of equal size
Nick
# Distributing items randomly into groups of equal size

(Asked by: username_0 on 2011-07-18)

Given n items (20% type A, 80% type B), I'm looking for a way to distribute them randomly into g groups of equal size. It must be possible for one group to end up with As in the majority but it must not be inevitable. I.e. If I was using binomial distribution, it would be extremely unlikely (with large values of n) to get a group in which the proportion of As was far from 20%. With uniform distribution between 0 and n/g, the first group to which As were allocated would almost always get many more As than the other groups (because the mean of the distribution function would be 50% rather than 20%).

I don't know much about stats and probability so this may be a stupid question but I suppose what I am asking for is a distribution function whose mean is 0.2 but which is likely to generate numbers between 0 and 0.2 and numbers between 0.2 and 1 with equal probability as well.

**Tags:** pr.probability, st.statistics
> **Comments:**
> **username_1**: I do not know what you mean.  Why doesn’t the uniform distribution on [0,0.4] satisfy your condition in the second paragraph?  
> **username_0**: I need it to generate 1 with some non-zero probability too. Uniform over [0,0.4] will never give you anything more than 0.4 right?  
> **username_2**: By your own constraints, you're requiring 0.2 to be the mean and the median of the distribution. One way to achieve this is to place a uniform distribution on [0,0.2] and construct a (probably exponential) distribution on [0.2,1] whose mean is at 0.3. Taking the average of these distributions will yield what you want.  
> **username_1**: “I need it to generate 1 with some non-zero probability too.”  Where did you state that requirement?  
> **username_0**: I feel that "it must be possible for one group to end up with As in the majority" and "numbers between 0.2 and 1" suggest it. Maybe not :D.  
> **username_3**: I feel that this question might be better suited for: http://stats.stackexchange.com/  
> **username_4**: I don't understand the question, but, just as a long shot, are you looking for something like the [multinomial distribution](http://en.wikipedia.org/wiki/Multinomial_distribution)?  It generalizes the binomial distribution so that you can partition into more than two sets.  

---

## 1 answers

### Answer by username_5 on 2011-07-19. Score: 1

*Given n items (20% type A, 80% type B), I'm looking for a way to distribute them randomly into g groups of equal size.*

To a statistician there is an unambiguous meaning to this statement. Which is to take `n` items, mark 20% of them as being of type A, shuffle them, then pull off groups of size `n/g`. For large `n` the resulting distribution will be very close to the binomial one. But it won't exactly be the binomial distribution. In fact there is a persistent bias towards being even more even than the binomial distribution, because when one thing of type A goes into a group it fills the group up a bit and makes it less likely that the next thing will go into that group.

It is straightforward to write code to create a list of things, perform a shuffle, and then pull out the groups. This will run in time `O(n)`.


---

