//returns a uniformly random ulong between Min and Max without modulo bias public static ulong NextULong(this Random Rng, ulong Min, ulong Max, bool inclusiveUpperBound = false) { ulong range = Max - Min; if (inclusiveUpperBound) { if (range == ulong.MaxValue) { return(Rng.NextULong()); } range++; } if (range <= 0) { throw new ArgumentOutOfRangeException("Max must be greater than Min when inclusiveUpperBound is false, and greater than or equal to when true", "Max"); } ulong limit = ulong.MaxValue - ulong.MaxValue % range; ulong r; do { r = Rng.NextULong(); } while (r > limit); return(r % range + Min); }
//returns a uniformly random ulong between ulong.Min and Max without modulo bias public static ulong NextULong(this Random Rng, ulong Max, bool inclusiveUpperBound = false) { return(Rng.NextULong(ulong.MinValue, Max, inclusiveUpperBound)); }