#pragma once #include // sometimes we need stateless normal distribution... /* * normal distribution with Box-Muller transform * http://www.design.caltech.edu/erik/Misc/Gaussian.html */ template static inline T StdNormalDistribution(TRng&& rng) noexcept { T x; T y; T r; do { x = (T)rng.GenRandReal1() * T(2) - T(1); y = (T)rng.GenRandReal1() * T(2) - T(1); r = x * x + y * y; } while (r > T(1) || r <= T(0)); return x * std::sqrt(-T(2) * std::log(r) / r); } template static inline T NormalDistribution(TRng&& rng, T m, T d) noexcept { return StdNormalDistribution(rng) * d + m; } // specialized for float, double, long double template T StdNormalRandom() noexcept; template static inline T NormalRandom(T m, T d) noexcept { return StdNormalRandom() * d + m; }