algorithm - Random distribution between evenly sized buckets without repetition -


problem

i have n items of various types evenly distributed own buckets determined type. want create new list that:

  1. randomly picks each bucket
  2. does not pick same bucket twice in row
  3. each bucket must have (if possible) equal amount of representation in final list
  4. not using language specific libraries (not implemented in language)

example

i have 12 items of 4 distinct types means have 4 buckets:

bucket - [a, a, a] bucket b - [b, b, b] bucket c - [c, c, c] bucket d - [d, d, d] 

what want

a list of above items in random distribution without characters repeating size between 1 , n.

12 items: a, d, c, a, b, a, c, d, c, b, d, b  8 items: c, a, d, a, b, d, c, b  4 items: c, b, d,  3 items: b, c, (skipping d) 

i trying while loop generates random integers until next bucket isn't equal used bucket, seems inefficient, , hoping else might have better algorithm solve problem.

you generate random list of buckets, , randomly pick in order, removing bucket list when pick it. when list empty, regenerate random list of buckets, repeating until pick desired number of items.

can repeat items buckets? if pick 1st "a" bucket first time around, can pick 2nd time? that'll change solution.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -