Create a number between specific values
3 ビュー (過去 30 日間)
古いコメントを表示
I want to create a random or not value between specific values:
I have three double a,b,c a>b>c
and i want d number to be (a+c)/2<d<a
0 件のコメント
採用された回答
Jan
2018 年 3 月 9 日
編集済み: Jan
2018 年 3 月 9 日
A random value between the two limits:
lim1 = (a + c) / 2;
lim2 = a;
d = lim1 + rand * (lim2 - lim1)
3 件のコメント
Walter Roberson
2018 年 3 月 9 日
Yes. rand() can never be exactly 0 or exactly 1, so d can never be exactly lim1 or exactly lim2.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Random Number Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!