I'm currently working on a kinetic Monte Carlo simulation in Python, so I need to generate pseudo-random numbers between 0 and 1 that follow the uniform distribution, but I'm searching to obtain at some point numbers less than E-1, for example, 0.001. I know that it won't be common, because they are random numbers after all, but my problem started in the implementation of Monte Carlo.
The problem in my Monte Carlo simulation, briefly is, I have one constraint_probability=c and one pseudo-random number=r, but because of the dynamics of my problem, I have the condition that my code only run if r < c. If I make for example c=0.001, my code never run.
My first thought was to use random.uniform
, but I found that the numbers obtained were at least with an order of E-2.
Later, I thought that my problem could be solved by making the following function:
from scipy.stats import uniform
def numrand():
vec=np.linspace(uniform.ppf(0),uniform.ppf(1), 10000)
return random.choice(vec)
I don't know if it's possible to obtain random numbers less than E-1 or if is another way to make my code run.
You can tell
np.random.uniform
the max and min value that you want. Since you seem to want numbers of the order ~10-5, ask formin=1e-5
andmax=1e-4
:Since samples are uniformly distributed over the half-open interval
[min, max)
, you can rest assured that any number you get from the distribution will be of the order 10-5This should also work with other distributions.