We can generate random numbers in an interval [a,b] easily if we want to make it uniformely:
A=rand()*(b-a) + a
where rand()
is a function which can generate a uniform random number between 0 and 1. so A
is a random number in [a,b]
.
For generating a random number based on a distribution function like y=x-x^2
, i faced a problem.
I would like to use a method mentioned here. But i am not interested to use the python function inverse_cdf(np.random.uniform())
.
I can compute the CDF of function "y" by an integration over 0 and X and i call it "f". But when i put the rand() function(a number between 0 and 1) into the inverse function of f, i get a complex number! It means: A=f^(-1) (rand())
returns a complex number.
Is it a correct way for generating a random number based on a distribution function?
Aucun commentaire:
Enregistrer un commentaire