random integer between 0 and 15 with equal probability
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Matt J
le 15 Juil 2013
Modifié(e) : Matt J
le 15 Juil 2013
B=randi([0,15])
7 commentaires
Stephen23
le 31 Août 2015
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.
Plus de réponses (2)
Jan
le 15 Juil 2013
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 commentaires
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!