jeudi 22 avril 2021

Generate random number that follows a probability distribution

I have a probability distribution described from a function, let's say a gaussian distribution (with coefficient 1/sqrt(pi), that makes the following area 1):

import math
D = lambda x: pow(math.e, -pow(x,2)) / math.sqrt(math.pi)

The previous function would plot the following graph enter image description here

If I used that gaussian function as a probability distribution I would have more probability to receive a 0 back than any other number.

Is there a way to generate a random number that follows that distribution?




Aucun commentaire:

Enregistrer un commentaire