How i can insert a random integer between two numbers?

I have a variable and i want it to take a randome integer between numbers 2 and 101

回答 (2 件)

Thomas Koelen
Thomas Koelen 2015 年 4 月 22 日
編集済み: Thomas Koelen 2015 年 4 月 22 日

0 投票

a=uint16(2+rand*99)
Star Strider
Star Strider 2015 年 4 月 22 日

0 投票

The randi function is perfect for this:
rv = randi([2 101]);

カテゴリ

ヘルプ センター および File ExchangeRandom Number Generation についてさらに検索

質問済み:

2015 年 4 月 22 日

回答済み:

2015 年 4 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by