how to generate random number between 10^-6 to 10^-50

4 ビュー (過去 30 日間)
Sun Heat
Sun Heat 2018 年 3 月 29 日
コメント済み: John D'Errico 2018 年 3 月 29 日
i use A + (B-A)*rand(1,N) this but it doesn't help me in my matter...every time it generate number near to the minimum value it not goes to 10^-40.

採用された回答

John D'Errico
John D'Errico 2018 年 3 月 29 日
編集済み: John D'Errico 2018 年 3 月 29 日
RAND produces a UNIFORMLY distributed random number.
Do you know what the probability that a uniformly distributed random number, when selected from the interval [1e-40,1e-6], will actually lie in the sub-interval [1e-40,1e-39]?
Roughly...
(1e-39 - 1e-40)/(1e-6 - 1e-40)
ans =
9e-34
I said roughly because MATLAB cannot actually compute the difference (1e-6-1e-40) completely accurately in double precision, but to compute the number exactly would require more effort than it is worth given the tiny difference.
So seriously, what would you expect? If you were to compute many billions of such numbers, you would still expect never to see such a result. Worse, it would never actually happen anyway, since that range of numbers is wider than the range you can compute with doubles.
Instead, you might decide to compute numbers randomly and uniformly in the interval [-40,-6]. Then raise 10 to that power. The result will NOT be uniform of course. It will have the properties that you seem to want however.
  12 件のコメント
Sun Heat
Sun Heat 2018 年 3 月 29 日
thanx
John D'Errico
John D'Errico 2018 年 3 月 29 日
I fell asleep and write -40 instead of -50. Same thing, but even worse. Regardless, the answer is to work in the form of powers of 10.

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by