static private SampleBoxMuller ( |
||
rnd | The random number generator to use. | |
리턴 | double>.Tuple |
/// <summary> /// Samples standard 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="dof">The degrees of freedom for the standard student-t distribution.</param> /// <returns>a random number from the standard student-t distribution.</returns> private static IEnumerable <double> DoSamples(Random rnd, double dof) { while (true) { var n = Normal.SampleBoxMuller(rnd).Item1; var g = Gamma.Sample(rnd, 0.5 * dof, 0.5); yield return(Math.Sqrt(dof / g) * n); } }