random - Faster calculation of whether an unlikely event occurs, in Python -
I have a simulation in which I have to check more when an unexpected event occurs
If the barrier of the event is 1 in n, then my code looks like this:
if random.randint (1, int (n)) == 1: do_stuff
That is, randomly generate an integer from 1 to n, and check that it is 1 (can choose any value in the range).
I doubt that it can be slow, does it look like a clear way to do somebody differently?
Hmm should have tried before asking this question, but I have come to know that: / P>
If numpy.random.randint (1, int (n)) == 1: do_stuff
Two or three times faster, of course, I still I am interested in seeing if there is any better way.
Comments
Post a Comment