Generate random numbers without repetition according to a probability distribution

1 次查看(过去 30 天)
The function randsrc can be used to generate random numbers according to a certain probabiluity distribution but it allows repetition for the generated numbers. I want a function that can generate random numbers according to a certain probability distribution but without repetition?

回答(1 个)

Jeff Miller
Jeff Miller 2021-3-8
I assume you mean a discrete distribution since the probability of repetition is zero in a continuous one.
In that case, the easiest way is to set up a markov chain that disallows state repetitions. Here is a simple example for a random variable that has 3 possible values (i.e, 1,2,3). The first row of P indicates that if the current observation is 1, then the next observation is equally likely to be 2 or 3. The second row of P says if the current observation is 2, then the next one will be 1 with probability 0.6 and 3 with probability 0.4. And so on. You can adjust the size of the P matrix and the values in it to model any discrete distribution you want, and the zero's on the diagonal indicate no repetitions.
P = [ 0 0.5 0.5;
0.6 0 0.4;
0.8 0.2 0];
mc = dtmc(P);
X = simulate(mc,10)

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by