4 ms·
from random import random sum([(random()*4+1)**3 for x in xrange(1000000)])/1000000 => ~39 Weird.
by solve 13y ago
from random import random
sum([(random()*4+1)**3 for x in xrange(1000000)])/1000000
=> ~39
Weird.
- bluetech 13y agosum(random.uniform(1, 5)**3 for i in range(10000)) / 10000 Many people don't know that the random module allows to sample from many distributions directly without having to construct your own.
- hollerith 13y agoI like the first version better because everyone knows what infix * and + do.
- saucetenuto 13y agoI like the second version better because it taught me something I didn't know.