1

How can I generate K uniform random numbers with constant sum S in MATLAB? Number must be positive and maximum is S. Please help me.

sharafi
  • 531
  • 1
  • 7
  • 19
  • Related: http://stackoverflow.com/questions/21213139/generate-nonnegative-random-number-matlab – herohuyongtao Jan 19 '14 at 14:36
  • Does my strategy in C work for you? http://stackoverflow.com/a/18701068/2564301 -- e.g., to generate *K* random numbers adding up to *S*, you can set constraints on each *next* number to be generated, all the way up to *K*-1 (and number *K* is *S*-(total so far). – Jongware Jan 19 '14 at 14:40
  • There are multiple ways to do this. Do you want all the marginal distributions to be uniform? In any case, check on the mathematics site as it contains potential solutions also. – soakley Jan 19 '14 at 14:46

0 Answers0