/// <summary> /// Sample from the distribution tail (defined as having x >= __R). /// </summary> /// <returns></returns> private double SampleTail() { double x, y; do { // Note. we use NextDoubleNonZero() because Log(0) returns NaN and will also tend to be a very slow execution path (when it occurs, which is rarely). x = -Math.Log(_rng.NextDoubleNonZero()) / __R; y = -Math.Log(_rng.NextDoubleNonZero()); }while (y + y < x * x); return(__R + x); }