3 ms·
That’s a neat solution, my instinct would have been futzing with the universal distribution of Math.random() into a normal distribution (incurring even more cos
by CraigJPerry 5y ago
That’s a neat solution, my instinct would have been futzing with the universal distribution of Math.random() into a normal distribution (incurring even more cost than the Math.log() call in the process).
- jtolmar 5y agoIf I recall correctly, this will get you a standard deviation of 1. let result = 0; for (let i = 0; i < 6; i++) { result += Math.random() - Math.random(); } return result; Obviously this costs 12x as much as Math.random() itself, but it sure is simple. (It'll also never return anything more than 6 standard deviations away from the mean, but it's not like you actually want that in most applications.)