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
Asked
Active
Viewed 1,214 times
-3
-
if their sum is 1 you dont need to generate 2 numbers. – bla Jul 16 '17 at 06:29
-
4Once you have a distribution of numbers between 0 and 1, you can impose your sum condition by dividing each number by the sum of them all. – Steve Jul 16 '17 at 07:13
-
1If the numbers are all different, they aren't as random any more – Mad Physicist Jul 16 '17 at 14:41
-
1And if you impose the condition that the sum is `1`, their distriution functions may be altered (see [this](https://stackoverflow.com/a/8068956/2586922)) – Luis Mendo Jul 16 '17 at 22:03
-
@MadPhysicist What do you mean by "If the numbers are all different, they aren't as random any more"? – Severin Pappadeux Jul 19 '17 at 20:39
-
Your sequence has a restriction on it preventing it from containing some numbers. That makes it less random. – Mad Physicist Jul 19 '17 at 21:04
-
@MadPhysicist which ones? Below I posted solution via Dirichlet distribution, with \vec{alpha} = 1 all marginal distributions will be U(0,1). – Severin Pappadeux Jul 20 '17 at 01:42
1 Answers
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