Hey Bill,

If we have 100 apples, for example, and we need to distrubte the 100 apples
> randomly in 10 boxes, how can we do this in python?
>

I assume the only invariant is sum(box_apples_i) == 100 for 10 boxes?

Maybe the following would do?

from random import sample
partitions = [0] + sorted(sample(range(100), 9)) + [100]
print [b-a for a, b in zip(partitions, partitions[1:])]

best,
Tom

PS I'm not sure if this is the best mailing list for such a problem? Maybe
someone who knows could chip in.
_______________________________________________
EuroPython 2010 - Birmingham, 17-24 July 2010 - http://www.europython2010.eu
EuroPython mailing list
EuroPython@python.org
http://mail.python.org/mailman/listinfo/europython

Reply via email to