How to generate a random integer betwwen a and b inclusive.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Good morning, I would like to know How to generate a random integer betwwen 1 and 10 inclusive. the integer should be 1 or .... or 10
Thanks (I ve already done it before, but I lost the code).
0 Kommentare
Antworten (2)
Roger Stafford
am 6 Apr. 2016
Bearbeitet: Roger Stafford
am 6 Apr. 2016
x = 9*rand(n,1)+1;
As to "inclusive" this will never give exactly 1 or exactly 10. However if you intended to have an uniform distribution between 1 and 10 the theoretical probability of either extreme is appropriately zero.
Addendum: Ignore this solution. I didn't notice the word 'integer'.
1 Kommentar
Siehe auch
Kategorien
Mehr zu Random Number Generation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!