Skip to content Skip to sidebar Skip to footer

Random Integers From An Exponential Distribution Between Min And Max

I would like to generate random integers on an interval min to max. For a uniform distribution in numpy: numpy.random.randint(min,max,n) does exactly what I want. However, I would

Solution 1:

The exponential distribution is a continuous distribution. What you probably want is its discrete equivalent, the geometric distribution. Numpy's implementation generates strictly positive integers, i.e, 1,2,3,..., so you'll want add min-1 to shift it, and then truncate by rejecting/throwing away results > max. That, in turn, means generating them one-by-one add adding the non-rejected values to a list until you get the desired number. (You could also determine analytically what proportion you expect to be rejected, and scale your n accordingly, but you'll still likely end up a few short or with a few too many.)

It's possible to do this without rejection, but you'd have to create your own inversion, determine the probability of exceeding max, and generate uniforms to between 0 and that probability to feed to your inversion algorithm. Rejection is simpler even though it's less efficient.


Solution 2:

May be you can try summing up all the bias. Then the probability of generating an integer j= bias of j / total bias. You can use monte carlo simulation to implement this.


Post a Comment for "Random Integers From An Exponential Distribution Between Min And Max"