예제 #1
0
        /// <summary>
        /// Sample from the distribution tail (defined as having x >= __R).
        /// </summary>
        /// <returns>A new random sample from the Gaussian distribution tail.</returns>
        private static float SampleTail(IRandomSource rng)
        {
            float x, y;

            do
            {
                // Note. we use NextFloatNonZero() because Log(0) returns -Infinity and will also tend to be a very slow execution path (when it occurs, which is rarely).
                x = -MathF.Log(rng.NextFloatNonZero()) / __RF;
                y = -MathF.Log(rng.NextFloatNonZero());
            }while(y + y < x * x);
            return(__RF + x);
        }