EDIT
Random.NextDouble() will not give the expected results!
As Kyle suggests in the comments below, the implementation of Random.NextDouble()
maps an int
to the interval [0.0 , 1.0), effectively making my code equivalent to r.Next( 0, Int32.MaxValue ) == 0
. Adding more zeroes to will not affect the probability of the result being false.
Use one of the other answers, or use this code to generate a ulong (range 0-18446744073709551615) from System.Random
.
var r = new Random();
var bytes = new byte[8];
r.NextBytes(bytes);
ulong result = BitConverter.ToUInt64(bytes, 0);
Original answer
Warning: will not work as expected, do not use! Provided merely for context.
Use Random.NextDouble()
instead: the result is a double between 0.0 and 1.0
var r = new Random();
var probablyFalseBool = r.NextDouble() < 0.0000000000001;
Vary the number of zeroes if necessary.