How can we generate random numbers between two negative values.

Can some plz help me to generate random nos between two negative values like [-5,-1.670000000000000]

 採用された回答

KSSV
KSSV 2021 年 1 月 11 日

2 投票

a = -5 ;
b = -1.670000000000000 ;
r = (b-a).*rand(1000,1) + a;

4 件のコメント

Kanika Bhalla
Kanika Bhalla 2021 年 1 月 11 日
thanks KSSV for the solution
KSSV
KSSV 2021 年 1 月 11 日
Thanks is accepting the answer ..:)
Kanika Bhalla
Kanika Bhalla 2021 年 1 月 11 日
is there any way to generate only one negative random no
like there is function for positive nos randi that generates one random no from a given range
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)
allPositive = 1×5
5 9 2 6 3
allNegative = randi([-10 -2], 1, 5)
allNegative = 1×5
-4 -6 -2 -9 -5
mixedSigns = randi([-6 6], 1, 5)
mixedSigns = 1×5
-2 1 6 0 -3
If you want to generate normally distributed or uniformly distributed numbers, see the documentation pages for the randn and rand functions respectively.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDesign and Simulate SerDes Systems についてさらに検索

質問済み:

2021 年 1 月 11 日

コメント済み:

2021 年 1 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by