/// <summary> /// Generate a t-distributed <see cref="double"/>. /// </summary> public static double StudentT(this IRandom random, double degreesOfFreedom) { if (degreesOfFreedom <= 0) { throw new ArgumentOutOfRangeException( "degreesOfFreedom", degreesOfFreedom, "Degrees of freedom must be positive."); } // See Seminumerical Algorithms by Knuth double y1 = random.Normal(); double y2 = random.ChiSquared(degreesOfFreedom); return(y1 / Math.Sqrt(y2 / degreesOfFreedom)); }