I try to generate N
numbers of random number from 0 to 1. This can be achieved via the rand
function, but how to constraint the mean of all the N
numbers is 1? The following code will generate a unit mean, but it has exceeded (<0
or >1
) the range I wanted (0<pp<1
).
N=100;
p=rand(N,1);
pp=p-(mean(p)+1)
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire