e藏在哪里?

e约等于2.718,是和pi齐名的自然常数。

在任何一个均匀随机器中,都藏着e。

import random


def count():
    rand_max = 1024
    k = 0
    s = 0
    while s < rand_max:
        k += 1
        s += random.randint(0, rand_max)
    return k


s = 0
epoch = 1000000
for i in range(epoch):
    s += count()
print(s / epoch)

2.717831

http://mathworld.wolfram.com/UniformSumDistribution.html

猜你喜欢

转载自www.cnblogs.com/weiyinfu/p/9938853.html