How can we generate random numbers between two negative values.
12 ビュー (過去 30 日間)
古いコメントを表示
Can some plz help me to generate random nos between two negative values like [-5,-1.670000000000000]
0 件のコメント
採用された回答
KSSV
2021 年 1 月 11 日
a = -5 ;
b = -1.670000000000000 ;
r = (b-a).*rand(1000,1) + a;
4 件のコメント
Steven Lord
2021 年 1 月 11 日
The randi function generates random integer values in a specified range. Nothing about the function limits it to only being able to produce random positive integer values.
allPositive = randi([2 10], 1, 5)
allNegative = randi([-10 -2], 1, 5)
mixedSigns = randi([-6 6], 1, 5)
If you want to generate normally distributed or uniformly distributed numbers, see the documentation pages for the randn and rand functions respectively.
その他の回答 (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!