News for hackers. Stuff that matters.
Re:How many draws of a random number [0,1] are needed to sum... by __herson__ on Sunday February 24, 2013 @02:24PM (#5275509)
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);

There are no comments on this comment yet.