If you have the RDRAND command RDRAND for the x86_64 processor:
#include <immintrin.h> #include <cstdint> ... bool randBool() { uint64_t val; if(!_rdseed64_step(&val)) { printf("Error generating hardware random value\n"); } return bool(val&1); }
However, this takes 63 of the 64 generated pseudo-random bits. If you need a higher speed, call _rdseed64_step() once in 64 random bit generators, but change the bit in each generation: val&(1<<0) , val & (1<<1) , val & (1<<2) , val & (1<<3) , ..., val & (1<<i) , ..., val & (1<<63) .
Serge Rogatch Jul 06 '17 at 9:00 2017-07-06 09:00
source share