In python random
module, the expovariate()
function generates floating point numbers which can be used to model inter-arrival times of a Poisson process. How do I make use of this to generate integer times between arrival instead of floating point numbers?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
jonrsharpe already kind of mentioned it, you can just let the function generate floating point numbers, and convert the output to integers yourself using int()
This
Should then be typed as
Another example
The examples above use list comprehension to generate multiple results in one line. Can of course be reduced to
Note that if you pass a higher number to
.expovariate()
you are more likely to get smaller floating points as result, and when usingint()
to convert the floats to integers, numbers that are between 0 and 1 will get converted to 0.