A selection of blocks random on stage

maybe someone can help me a little with a function for this:

i have a number of movieclips. let’s say 20.
every movieclip contains one black block - and they’re all different in size.

i want to put them one by one in random order on the stage until the space on the stage is filled like this:
http://www.kulsdom.com/newstoday/blocks.gif

in other words: when only 4 movieclips fits on the stage it shows 4 movieclips, when 8 movieclips fits… etc etc

and i don’t want them to overlap each other…
how could this be done?