Generate random numbers without repetition according to a probability distribution
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Antworten (1)
Jeff Miller
am 8 Mär. 2021
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)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Random Number Generation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!