-3

How to generate different random numbers according to probability distribution functions, using Matlab, where the generated numbers must be different, between 0 and 1 and the sum of these numbers is equal to 1

shdotcom
  • 157
  • 1
  • 11

1 Answers1

1

This is called Dirichlet distribution, and below is the code to sample from it. Simplest case is when all parameters are equal to 1

----------------- taken from here ---------------------

The Dirichlet is a vector of unit-scale gamma random variables, normalized by their sum. So, with no error checking, this will get you that:

a = [1.0 1.0 1.0];
n = 10000;
r = drchrnd(a,n)

function r = drchrnd(a,n)
p = length(a);
r = gamrnd(repmat(a,n,1),1,n,p);
r = r ./ repmat(sum(r,2),1,p);
Severin Pappadeux
  • 18,636
  • 3
  • 38
  • 64