public static double NextDouble(ref ulong state) { // generate 52 random mantissa bits and an unbiased exponent of 0 ulong dval = (NextUInt64(ref state) & 0xFFFFFFFFFFFFFUL) | 0x3FF0000000000000UL; double zeroToOne = DoubleULongUnion.ReinterpretCast(dval) - 1.0; CoreException.Assert(zeroToOne >= 0.0f && zeroToOne < 1.0); return(zeroToOne); }
public static double NextDouble(ref ulong state, double minValue, double maxValue) { CoreException.Assert(maxValue > minValue); var dval = (NextUInt64(ref state) & 0xFFFFFFFFFFFFFUL) | 0x3FF0000000000000UL; double zeroToOne = DoubleULongUnion.ReinterpretCast(dval) - 1.0; double retval = minValue + ((maxValue - minValue) * zeroToOne); CoreException.Assert(retval >= minValue && retval < maxValue); return(retval); }