我想使用 RNGCryptoServiceProvider 作为我的随机数来源。由于它只能将它们输出为字节值数组,我如何才能将它们转换为 0 到 1 double 值,同时保持结果的一致性?
最佳答案
byte[] result = new byte[8];
rng.GetBytes(result);
return (double)BitConverter.ToUInt64(result,0) / ulong.MaxValue;
关于c# - 如何从随机字节数组值中获取随机 double 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/403572/