我想用RNGCryptoServiceProvider作为我的随机数的来源。因为它只能输出它们作为字节值数组我怎样才能将它们转换为0到1,而结果preserving一致性?
双重价值 解决方案 byte []的结果=新的字节[8]。
rng.GetBytes(结果);
返程(双)BitConverter.ToUInt64(结果,0)/ ulong.MaxValue;
I would like to use RNGCryptoServiceProvider as my source of random numbers. As it only can output them as an array of byte values how can I convert them to 0 to 1 double value while preserving uniformity of results?
解决方案byte[] result = new byte[8];
rng.GetBytes(result);
return (double)BitConverter.ToUInt64(result,0) / ulong.MaxValue;