I need to generate random numbers, but from as wide a range as possible (64 bit at least). I don\'t care if the distribution is perfect, so std::rand()
would wo
Not C++11, but easy enough
((unsigned long long)rand() << 32) + rand()
Here we generate two parts of int64 as int32's
As JasonD
pointed out, it assumes that rand()
generate 32bit integer. It' spossible to xor
rand() << x
, rand() << (2*x)
, rand() << (3*x)
, etc, where x
<= bit's in generate by rand()
number`. It should be OK too.