3 ms·
Always 2.7~ with 10,000 trials function sumToOne() { var acum = 0, count = 0; do { count++; acum += Mat
by __herson__ 14y ago
Always 2.7~ with 10,000 trials
function sumToOne() {
var acum = 0,
count = 0;
do {
count++;
acum += Math.random();
} while (acum <= 1)
return count;
}
var avg = 0,
nTimes = 10000;
for (var x = 0; x < nTimes; x++) {
avg += sumToOne();
}
console.log(avg / nTimes);