random integer between 0 and 15 with equal probability
4 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to generate a random integer between 0 and 15.
I have written the following code:
b=0;
B=15;
B = b + (B-b) * rand
Is it right?
Also, will the random integer generated from the above code have equal probability? Is not, how should the code be modified?
0 个评论
采纳的回答
Matt J
2013-7-15
编辑:Matt J
2013-7-15
B=randi([0,15])
7 个评论
Stephen23
2015-8-31
When you read the randi documentation, its description states on the very first line "Uniformly distributed pseudorandom integers". This means the integers have equal probability. It also means that you should learn to read the documentation, because it tells you how MATLAB works.
更多回答(2 个)
Jan
2013-7-15
This is not a hard proof, but a strong hint already:
b = 0;
B = 15;
R = b + (B-b) * rand(1, 1e6);
histc(R, unique(R))
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!