如何获得随机double值了随机字节数组值吗?数组、字节、如何获得、double

2023-09-04 02:44:30 作者:你演得这么真我怎么区分

我想用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?

解决方案 输出double形数据,用 什么

byte[] result = new byte[8];
rng.GetBytes(result);
return (double)BitConverter.ToUInt64(result,0) / ulong.MaxValue;