For instance, say I picked randomly:

.248727...

.671823...

These add to only .92...

so I pick another:

.31333

Ok that exceeded 1.0 when you add all 3 so 3 goes on a list. Then I do this, say 100,000 times and average the number of tries and it came out to in one case:

2.71859

which is very close to the correct value of e:

2.71828...

I've heard many facts about e but I've never heard this particular simple one so I thought I'd post it. Here is some python source code:

import random

def trial():

sum = 0

counter = 0

while sum < 1:

sum+=random.random()

counter+=1

return counter

def main():

t = 0.0

for i in range(0, 100000):

t+=trial()

print t/100000

main()

## No comments:

## Post a Comment