How i can insert a random integer between two numbers?

1 view (last 30 days)
I have a variable and i want it to take a randome integer between numbers 2 and 101

Answers (2)

Thomas Koelen
Thomas Koelen on 22 Apr 2015
Edited: Thomas Koelen on 22 Apr 2015
a=uint16(2+rand*99)

Star Strider
Star Strider on 22 Apr 2015
The randi function is perfect for this:
rv = randi([2 101]);

Categories

Find more on Random Number Generation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!