How to distribute $N$ items into $M$ groups the "most" random way?

135 Views Asked by At

There are $N$ "items" $s_1, s_2, ..., s_N$ and $M$ "buckets" with capacities $c_1, c_2, ..., c_M$ such that $\sum_{j=1}^{M}c_j = N$. In a document I'm reading (some industry application), an algorithm of random filling of buckets is roughly described as following.

Algorithm 1.

until all buckets are full:

  • determine random bucket $m$, $1\leq m\leq M$
  • determine random item $i$, $1\leq i\leq N$
  • put item $i$ into bucket $m$

I would do this as following, though. (We work with Python and want to avoid for-loops in the programming code).

Algorithm 2.

  • randomly permute the indices of items
  • put the first $c_1$ items into 1st bucket, the next (starting from $c_1+1$) $c_2$ items into 2nd bucket and so on.

Are these two approaches equivalent in the sense of randomness (I guess)? Or do two random pickings in Algorithm 1 make it "more" random than the second one?

1

There are 1 best solutions below

0
On

Sounds to me that the existing solution allows for duplicates while yours doesn't. Other than that both seem uniformly distributed from symmetry.