不能算是纯原创吧,算半个转载好了,但保证一定能用!
首先导入模块
import mathimport random
泊松分布
def poisson(L):"""poisson distributionreturn a integer random number, L is the mean value"""p = 1.0k = 0e = math.exp(-L)while p >= e:u = random.random() #generate a random floating point number in the range [0.0, 1.0)p *= uk += 1return k-1
负指数分布
def expntl(L):"""negative exponential distributionreturn a double random number, L is the mean value"""u = random.random()return -L * math.log(u)
大可以循环个N次求平均来测试正确性!
如果觉得《python学习笔记:泊松分布和负指数分布随机数的python实现》对你有帮助,请点赞、收藏,并留下你的观点哦!