等价于Windows上的/dev/urandom? [英] Equivalent of /dev/urandom on Windows?

查看:615
本文介绍了等价于Windows上的/dev/urandom?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序想要获取一个随机数,最好是带有熵(如果有的话),但是不需要密码质量,并且想要确保在系统熵池耗尽时(例如在服务器上)该调用不会阻塞在一个农场).

My application would like to get a random number, preferably with entropy if available, but does not need cryptographic quality, and would like to do ensure that the call does not block if the system entropy pool is depleted (e.g. on a server in a farm).

我知道

I am aware of CryptGenRandom, but its behaviour with respect to blocking under adverse entropy conditions is not specified.

在Unix上,/dev/urandom支持此用例. Windows上是否有可用的等效功能?我宁愿避免仅使用非系统RNG来获取非阻塞语义.

On Unix, /dev/urandom supports this use case. Is there equivalent functionality available on Windows? I would prefer to avoid using a non-system RNG simply to get non-blocking semantics.

推荐答案

对于玩具应用程序,您可以使用标准库函数 rand_s() 标准库函数.

For a toy application, you could use the standard library function rand(), but the implementation on Windows is of notoriously poor quality. For cryptographically secure random numbers, you can use the rand_s() standard library function.

更好的选择是在程序中包括一个合适的伪随机数生成器. Mersenne Twister 是IMO的不错选择,尤其是因为有许多可用的实现(包括C ++ 11标准库和Boost中.

A better bet is simply to include a suitable pseudo-random number generator in your program. The Mersenne Twister is a good choice IMO, particularly as there are plenty of available implementations (including in the C++11 standard library and in Boost).

这篇关于等价于Windows上的/dev/urandom?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆