Make HepRandomEngine std conformant (improvement)
I suggest to make HepRandomEngine interface conformant to std::random.
as example I coded this simple wrapper
#include <cstdint>
#include <limits>
#include <cstring>
#include "CLHEP/Random/RandomEngine.h"
// a wrapper to make a HepRandomEngine std conformant
class CLHEP2STDRandom {
public:
using result_type = uint64_t;
CLHEP2STDRandom(CLHEP::HepRandomEngine & engine) : m_engine(engine) {}
// MixMax is limited to 61 bits (and will reimplement operator() to return getNext() )
static constexpr result_type u61 = std::numeric_limits<result_type>::max() >> (64-61);
// to be overridden by those who generate uint64_t natively...
virtual result_type operator()() {
uint64_t u1 = uint32_t(*this);
uint64_t u2 = uint32_t(*this);;
u1 <<=32;
return u1 | u2;
}
static constexpr result_type min() { return 0; } // actually 1??
static constexpr result_type max() { return u61; }
private:
CLHEP::HepRandomEngine & m_engine;
};
There are of course two limitations:
- It assumes all CLHEP generators to have at least 53 bits of "entropy"
- Cannot "export" more than 53 bits with the current interface of HepRandomEngine
Lifting these limitations making all CLHEP generators able to provide a guaranteed number of random bits larger than 53 would be of course ideal.