MATLAB: Random number generation for known sum

rand

i what do generate some 15 random numbers that sum for each separate value of say, 60 , 70, 40, 65. How would i go abouts this?
sum = [60 70 40 65];
n=15;
b = [ ];
for i = 1:1:n,
a = randi([1,??]);
b = [b a];
end

Best Answer

n=60;
m=1:n;
a=m(sort(randperm(60,15)));
b=diff(a);
b(end+1)=60-sum(b)
sum(b)
Related Question