How to generate uniformly distributed random integers?
이전 댓글 표시
I've been using "ceil(4*rand)" to generate random integers from 1 to 4. But when I tried to check the uniformity, I found that I do not get a probability of 0.25 and instead have p(1)=0.24997, p(2)=0.25102, p(3)=0.24949 and p(4)=0.24951 after generating 10,00,000 values. Is it good enough to say that it's uniform?
채택된 답변
추가 답변 (2개)
Pannir Selvam Elamvazhuthi
2011년 8월 28일
0 개 추천
댓글 수: 1
the cyclist
2011년 8월 29일
No problem on the late response. However, you should consider deleting this "answer" (because it is not answer), and making it a comment on my answer.
Sergio Enrique Pinto Castillo
2020년 7월 28일
편집: Sergio Enrique Pinto Castillo
2020년 7월 28일
0 개 추천
I think the answer is:
Num = 1000;
vec = randi([1 Num],1,Num);
This instruction generate a vector with random uniformly distributed integers between 1 and 1000
카테고리
도움말 센터 및 File Exchange에서 Uniform Distribution (Continuous)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!