greg at cosc.canterbury.ac.nz
Sat Mar 10 10:16:52 CET 2007
Steven D'Aprano wrote:
> Last but not least, another possible algorithm is to start with a list of
> N numbers, regardless of whether or not they add to M, and then adjust
> each one up or down by some amount until they sum to the correct value.
Another possibility is to generate a list of N non-random
numbers that sum to M, and then adjust them up or down
by random amounts. By performing up/down adjustments in
pairs, you can maintain the sum invariant at each step.
So then it's just a matter of how long you want to go
on fiddling with them.
More information about the Python-list