14 CRNG32( ) : n(), key() { seed(123451); }
15 CRNG32(
const unsigned s ) : n(), key() { seed(s); }
16 void seed(
const unsigned s ) { n= 0; key= (s << 1) | 1; }
18 CRNG32& index(
const unsigned i ) { n= i;
return *
this;}
19 unsigned sample( ){
return hash(++n * key); }
21 unsigned sample_range(
const unsigned range )
25 unsigned divisor= ((-range) / range) + 1;
26 if(divisor == 0)
return 0;
30 unsigned x= sample() / divisor;
31 if(x < range)
return x;
36 unsigned operator() ( ) {
return sample(); }
37 static constexpr
unsigned min( ) {
return 0; }
38 static constexpr
unsigned max( ) {
return ~unsigned(0); }
39 typedef unsigned result_type;
42 unsigned hash(
unsigned x )
62 CRNG64( ) : n(), key() { seed64(0xc58efd154ce32f6d); }
63 CRNG64(
const uint64_t s ) : n(), key() { seed64(s); }
64 CRNG64(
const unsigned hi,
const unsigned lo= 0x40ba6a95 ) : n(), key() { seed(hi, lo); }
66 void seed(
const unsigned hi,
const unsigned lo= 0x40ba6a95 ) { seed64( uint64_t(hi) << 32 | uint64_t(lo) ); }
67 void seed64(
const uint64_t s ) { n= 0; key= (s << 1) | 1; }
69 CRNG64& index(
const uint64_t i ) { n= i;
return *
this;}
70 unsigned sample( ) {
return hash(++n * key); }
72 unsigned sample_range(
const unsigned range )
76 unsigned divisor= ((-range) / range) + 1;
77 if(divisor == 0)
return 0;
81 unsigned x= sample() / divisor;
82 if(x < range)
return x;
87 unsigned operator() ( ) {
return sample(); }
88 static constexpr
unsigned min( ) {
return 0; }
89 static constexpr
unsigned max( ) {
return ~unsigned(0); }
90 typedef unsigned result_type;
92 unsigned hash( uint64_t v )
95 v *= 0x7fb5d329728ea185;
97 v *= 0x81dadef4bc2dd44d;