Generate random numbers without repetition according to a probability distribution

2 ビュー (過去 30 日間)
Salwa Mostafa
Salwa Mostafa 2021 年 3 月 8 日
回答済み: Jeff Miller 2021 年 3 月 8 日
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 Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by