15 views (last 30 days)

John D'Errico
on 29 Mar 2018

Edited: John D'Errico
on 29 Mar 2018

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.

Guillaume
on 29 Mar 2018

Torsten is right

Then, as John explained in his last paragraph:

exponent = 6 + 44*rand(1, 30);

numbers = 10.^-exponent

Of course, the distribution will not be uniform at all.

And of course, adding 1 to numbers will cancel any number smaller than about 2e-16 ( eps(1))

John D'Errico
on 29 Mar 2018

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.