I know how to generate random numbers between 0 and 1 using the method of pseudo-random number generator.
var rng1 = new system Random (); Var random1 = rng1 Next repeat (); // generate a random double between 0 and 1.0
and how do I fill random byte array using a cryptographically safe random number generator. [] Bytes = new byte [8]; Var rng2 = new system Security. Cryptography RNGCryptoServiceProvider (); Rng2.GetBytes (byte); // generates 8 random bits
but how can I distribute the byte-array output evenly between 0 (inclusive) and 1 (unique) in a random number? Am I
It appears that because of the upside, the solution will be unequal distributions so far. For one distribution I thought that you want something like that.
// Step 1: 8 Fill an array with Random Bytes var rng = new RNGCryptoServiceProvider (); Var bytes = new bytes [8]; Rng.GetBytes (byte); // Step 2: bit-shift 11 and 53, var based on the Manthissa bits var = Bitakonar ToUINT64 (bytes, 0) / (1 <11); Double D = ul / (double) (1UL
Note that you can not divide UInt64 into UInt64.MaxValue, because there is not enough bits in one double, and there is no way to get unique output for all your inputs. is. So you can remove some bits.
Comments
Post a Comment