29 ms·
Unfortunately the elegance comes at a cost: Box-Muller is a lot slower due to the sqrt and log. Ziggurat's fast path (which can be hit arbitrarily rarely, by co
by dbaupp 11y ago
Unfortunately the elegance comes at a cost: Box-Muller is a lot slower due to the sqrt and log. Ziggurat's fast path (which can be hit arbitrarily rarely, by controlling the table size) is just some indexing and comparisons, making it amazingly fast.
Also, Ziggurat can be applied to any distribution with a decreasing PMF (e.g. it's also amazingly fast for the Exponential distribution), whereas Box-Muller relies on special properties of the Normal.
- redcalx 11y agoOne could say that the high level source code is elegant, but overall its use of log and sqrt invoke a lot of complex machinations (inside the CPU).
- semi-extrinsic 11y agoAlso, IIRC Box-Muller gives incorrect results if you're interested in sampling the tails of the Gaussian.
- onnoonno 11y agoIf you're not interested in the tails, there's also always (random()+random()+random()+random()-2.0)*sqrt(3.) as a cheap (in terms of brain power) Gaussian (sigma=1, mean=0) rough approximation :-)