Пример #1
0
        /// <summary>
        /// Samples student-t distributed random variables.
        /// </summary>
        /// <remarks>The algorithm is method 2 in section 5, chapter 9
        /// in L. Devroye's "Non-Uniform Random Variate Generation"</remarks>
        /// <param name="rnd">The random number generator to use.</param>
        /// <param name="location">The location (μ) of the distribution.</param>
        /// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
        /// <param name="freedom">The degrees of freedom (ν) for the distribution. Range: ν > 0.</param>
        /// <returns>a random number from the standard student-t distribution.</returns>
        static double SampleUnchecked(System.Random rnd, double location, double scale, double freedom)
        {
            var gamma = Gamma.SampleUnchecked(rnd, 0.5 * freedom, 0.5);

            return(Normal.Sample(rnd, location, scale * System.Math.Sqrt(freedom / gamma)));
        }