Possible Duplicate:
Random numbers that add to 100: Matlab
I am looking to do the following:
Generate several random numbers between 10 and 50.
Have the sum of the random numbers equal 500.
What I have so far is:
sum = 500
n=5
b = [ ]
for i = 1:1:n-1,
a = randi([10,50])
b = [b a]
end
n=5 is in there as an example and can equal anything.
I am looking for the sum of b to equal 500 (That could be the difference between 'sum = 500' and sum of the values before the sum equals 500 -- making the last number not actually random, which is ok)
b =
23 10 43 30