static_assert( __cplusplus > 2023'00 ); #include "fastRandom.h" #include #include namespace Alepha::Hydrogen ::detail:: fastRandom_m { namespace { struct FastRandomState { boost::random::taus88 fastRandomState{ std::random_device{}() }; std::uint32_t pool; int remainingBits= 0; void next() { pool= fastRandomState(); remainingBits= 32; } void refresh() { if( remainingBits == 0 ) next(); } std::uint32_t getBit() { refresh(); const std::uint32_t rv= pool & 1; --remainingBits; pool>>= 1; return rv; } std::uint32_t get( int count ) { std::uint32_t rv= 0; while( count-- ) { rv<<= 1; rv|= getBit(); } return rv; } }; thread_local FastRandomState fastRandom; } std::uint32_t exports::fastRandomBits( const int numBits ) { return fastRandom.get( numBits ); } }