- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
引自cppreference :
std::random_device is a non-deterministic random number engine, although implementations are allowed to implement std::random_device using a pseudo-random number engine if there is no support for non-deterministic random number generation.
有没有办法检查当前的实现是否使用 PRNG 而不是 RNG(然后说错误退出),如果没有,为什么不呢?
请注意,一点谷歌搜索表明至少 MinGW 以这种方式实现了 std::random_device
,因此如果 std::random_device
是真正的危险被使用。
---编辑---
此外,如果答案是否定的,并且有人可以就为什么没有这样的功能/特征/某物提供一些见解,我会非常感兴趣。
最佳答案
Is there a way to check whether current implementation uses PRNG instead of RNG (and then say exit with an error) and if not, why not?
有一个方法:std::random_device::entropy
如果它是根据随机数引擎实现的(也就是说,它是确定性的),将返回 0.0
。
来自标准:
double entropy() const noexcept;
Returns: If the implementation employs a random number engine, returns
0.0
. Otherwise, returns an entropy estimate for the random numbers returned byoperator()
, in the rangemin()
tolog_2(max() + 1)
.
关于c++ - 有没有办法检查 std::random_device 是否实际上是随机的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27886761/
我有一个包含两个随机源的类。 std::random_device rd; std::mt19937 random_engine; 我通过调用 std::random_device 为 std::mt
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 9 年前。 Improve t
我需要从不同的 C++ 随机数生成算法中获取数据,为此我创建了一些程序。其中一些使用伪随机数生成器,而另一些使用 random_device(非确定性随机数生成器)。下面的程序属于第二组: #incl
我对 c++11 随机库有点困惑。 我的理解:我们需要两个独立的概念: 随机引擎,可以是: 伪(需要种子)又名 PRNG 真正的随机数生成器 分布:它将从引擎获得的数字映射到特定的区间,使用特定的分布
是否保证 random_device 不会在每个新线程的相同内部状态下启动?那么下面的代码很可能给出两个不同的值? #include #include #include #include us
#include #include using namespace std; int main() { vector coll{1, 2, 3, 4}; shuffle(coll.
我看到很多人一起谈论安全和 std::random_device。 例如,here幻灯片 22。 根据 cppreference , std::random_device : std::random_
根据标准,std::random_device 按以下方式工作: result_type operator()(); Returns: A non-deterministic random value
典型的现代获取随机数的方法是这样的: std::random_device rd; std::mt19937 engine{rd()}; std::uniform_int_distribution<>
我有一些看起来有点像这样的代码: std::random_device rd; #pragma omp parallel { std::mt19937 gen(rd()); #prag
我试着解决这个问题: c++0x_warning.h:32: Fehler:#error This file requires compiler and library support for the
有人知道如何在 ubuntu 上安装 random_device 吗?安装了来自 repo 的所有 boost 包。 我收到的错误是: fatal error :boost/random/random
我尝试运行一个来自 cppreference 的简单示例关于std::random_device , 但在函数调用线上 d(rd1)程序进入无限循环,永不返回。 代码如下: #include #in
我正在使用 std::random_device 并想检查它的剩余熵。根据 cppreference.com: std::random_device::entropy double entropy()
我是 C++ 初学者,我对 C++0x 随机数生成器有疑问。我想使用 Mersenne twister 引擎来生成随机 int64_t 数字,并且我使用我之前找到的一些信息编写了一个函数: #incl
假设我有这个跨平台程序 #include #include int main() { std::random_device rd; std::cout dist(0, 9);
std::random_device 的拷贝构造函数被删除了,我不知道为什么。 我从 docs 中找到的唯一笔记是: 2) The copy constructor is deleted: std::
引自cppreference : std::random_device is a non-deterministic random number engine, although implementa
gcc implementation std::random_device 对我来说似乎很奇怪。具体来说,第 137 行: random_device::result_type random_
我在 Windows 中使用 g++ 和 MinGW 来编译我的 c++ 代码,它看起来像这样: std::mt19937_64 rng(std::random_device{}()); std::u
我是一名优秀的程序员,十分优秀!