MATLAB: Random numbers that sum up to a definite integer

random number generator

hi, i would like to generate a column vector using rand function e.g rand(5,1), so that none of the element is bigger than 1 and less than 0. and i want the sum of all the elements to equal 1 exactly. how do i do it?

Best Answer

Use randfixedsum.m function from the following link:
and write
randfixedsum(5,1,1,0,1)