Generate random numbers without repetition according to a probability distribution
조회 수: 7 (최근 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?
댓글 수: 0
답변 (1개)
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)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!