public double Sample(LocalRandom random) { const double epsilon = Double.Epsilon; generate = !generate; if (!generate) { return(z1 * Parameter + Mean); } double u1, u2; do { u1 = random.NextDouble(); u2 = random.NextDouble(); }while (u1 <= epsilon); var z0 = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2); z1 = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2); return(z0 * Parameter + Mean); }
public double Sample(LocalRandom random) { var u = random.NextDouble() - 0.5; return(Mean - Parameter * Math.Sign(u) * Math.Log(1 - 2 * Math.Abs(u))); }