I’m working with random numbers in python, the problem is the following; I have a variable, we can call it “x”, I want it to take values between [10^-6,10^-1], then I have the following line
x=np.random.uniform[1e-6,1e-1]
But it is only generating numbers like
0.123123 0.524234 0.0453454 0.9083405
It never generates numbers like
0.0002342 0.00002434 0.313123 0.000004234 0.034234
How can I generate the second type of random numbers? Generating random numbers of magnitudes 1e-1,1e-2,1e-3,1e-4,1e-5,1e-6
?
Advertisement
Answer
It appears that you are looking for logarithmically distributed data, where the log of the statistic is uniformly distributed. Knowing this you can construct these numbers easily:
import numpy as np exponent = np.random.uniform(-6, -1, 10000) x = 10**x
A histogram of x looks like this:
while a histogram of the log of x (which is equal to the exponent by construction) looks nice and uniform: