On Wed, 4 Mar 2009, YOhannes wrote:
what i want to do is to put them randomly into the list as long as the sum of all items in the list equals the size of the fixed value. this seems to be pretty difficult...since i use random i cant know what the next float will be. how to handle that? any experience with that issue ?
Make a random recursive partition of the fixed value, then shuffle it.
For example:
start with the list 16 (one element)
for each number in the list, throw dice to figure out whether you will replace it by two equal numbers. any new numbers shall have the same procedure reapplied to them (recursion), else I wouldn't be explaining it by saying "for each" when it's about a one-element list. this could give you, for example: 4 1 1 0.5 0.5 1 2 1 1 0.5 0.5 1 2
a fair shuffle could give any sequence with the same number of 0.5,1,2,4
elements in it, let's say 0.5 4 1 1 0.5 2 1 0.5 2 1 0.5 1 1.
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801, Montréal, Québec