Random number generation from uniform distribution
이전 댓글 표시
Good afternoon, I'm currently trying to generate random numbers from a uniform distribution, but I'm not sure how to input probabilities.
For example, Let S be uniformly distributed between 70 and 130:
a=70;
b=130;
S=a+(b-a).*rand
However, let's say we want to generate T which is uniformly distributed: between 0.1 and 1.0 (with probability 0.75) between 1.0 and 5.0 (with probability 0.25)
Is it possible to use the rand function as normal? i.e.
a=0.1;
b=1.0;
c=5.0
T=([a+(b-a).*rand]*0.75)+([b+(c-b).*rand]*0.25)
I appreciate any feedback.
댓글 수: 1
dpb
2014년 8월 14일
T=([a+(b-a).*rand]*0.75)+([b+(c-b).*rand]*0.25)
No, that's scaling the return value by the two probabilities, not the frequency. Need to scale values returned from rand <0.75 to range [a,b] and the rest to [b,c]
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!