MATLAB: Simple Matlab Random Number Generation

random numbers

I have to get 5 random numbers a1, a2, a3, a4, a5 where each a1, a2, a3, a4, a5 should be between [-0.5, 0.5] and sum i.e. a1 + a2 + a3 + a4 + a5 = 1.
How should I do it?

Best Answer

  • Create 5 arrays that have all possible combinations of these numbers then generate a random number that is between 1 and length of array and then use that value as the index for the array and viola, there's your number. The size of these arrays can be controlled by the resolution you go to.