vendredi 23 avril 2021

Random numbers with orders less than E-1

I'm currently working on a Monte Carlo simulation in Python, so I need to generate pseudo-random numbers, but the thing is, I need to generate numbers between 0 and 1, that follow the uniform distribution, but also with orders less than E-1, specifically, I'm searching numbers with orders of E-5.

My first thought was to use random.uniform, but I found that the numbers obtained were at least with an order of E-2 and also that's not too common.

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)

But I don know if it is the more efficient way to do it because I need to optimize my code the most possible.

I wanted to ask you if you can give me some ideas.




Aucun commentaire:

Enregistrer un commentaire