真正的随机数与C ++ 11和RDRAND [英] True random numbers with C++11 and RDRAND

查看:1490
本文介绍了真正的随机数与C ++ 11和RDRAND的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到,英特尔似乎已经纳入一个新的装配函数来获取硬件获得真正的随机数。该指令的名称是 RdRand ,但只有细节少量似乎访问它在互联网上:的 http://en.wikipedia.org/wiki/RdRand

我关于这个新指令及其利用C ++ 11的问题有以下几点:


  1. RdRand 真正的随机产生的随机数? (从不相关白噪声或量子过程产生的每一位?)


  2. 它是Ivy Bridge的处理器的特殊功能,将英特尔继续在新一代CP​​U来实现这个功能呢?


  3. 如何通过C ++ 11使用它?也许与的std :: random_device 但是编译器已经叫 RdRand 如果该指令是可用的?


  4. 如何检查是否 RdRand 当我编译程序真的叫?



解决方案

  1. 这当然取决于你的宇宙的决定来看,所以更多的是哲学问题,但许多人认为它是随机的。

  2. 只有英特尔就知道了,不过既然有需求,添加它,它可能会出现需求保持它

  3. 的std :: random_device 不需要是硬件驱动,即使是,它不使用所需 rdrand 。你可以问它的双熵()const的noexcept 成员函数,无论是硬件驱动或没有。使用 rdrand 因为这是一个Qoi相的问题,但我希望有提供给这么做每个理智的实现(我见过例如GCC这样做)。如果不确定,可以随时查询组装,而且硬件随机性等手段应该是足够好(还有其他专门的硬件可用)。

  4. 见上面,如果你有兴趣在其唯一的硬件是否使用,如果有兴趣的rdrand,扫描生成的机器code。

I have seen that Intel seems to have included a new assembly function to get real random numbers obtained from hardware. The name of the instruction is RdRand, but only a small amount of details seem accessible on it on Internet: http://en.wikipedia.org/wiki/RdRand

My questions concerning this new instruction and its use in C++11 are the following:

  1. Are the random numbers generated with RdRand really random? (each bit generated from uncorrelated white noise or quantum processes? )

  2. Is it a special feature of Ivy Bridge processors and will Intel continue to implement this function in the next generation of cpu?

  3. How to use it through C++11? Maybe with std::random_device but do compilers already call RdRand if the instruction is available?

  4. How to check whether RdRand is really called when I compile a program?

解决方案

  1. That certainly depends on your view of the determinism of the universe, so is more a philosophical question, but many people consider it being random.
  2. Only intel will know, but since there was demand to add it, its likely there will be demand to keep it
  3. std::random_device is not required to be hardware driven, and even if it is, it is not required to use rdrand. You can ask its double entropy() const noexcept member function whether it is hardware driven or not. Using rdrand for that is a QoI issue, but I would expect every sane implementation that has it available to do so (I have seen e.g. gcc doing it). If unsure, you can always check assembly, but also other means of hardware randomness should be good enough (there is other dedicated hardware available).
  4. See above, if you are interested in whether its only hardware, use entropy, if interested in rdrand, scan the generated machine code.

这篇关于真正的随机数与C ++ 11和RDRAND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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