gKit2 light
Loading...
Searching...
No Matches
PCG32I Struct Reference

Public Types

typedef unsigned result_type

Public Member Functions

 PCG32I (const unsigned s, const unsigned ss=2891336453u)
void seed (const unsigned s, const unsigned ss)
unsigned sample ()
unsigned sample_range (const unsigned range)
unsigned operator() ()

Static Public Member Functions

static constexpr unsigned min ()
static constexpr unsigned max ()

Public Attributes

unsigned x
unsigned key

Detailed Description

Definition at line 95 of file pcg.h.

Member Typedef Documentation

◆ result_type

typedef unsigned PCG32I::result_type

Definition at line 136 of file pcg.h.

Constructor & Destructor Documentation

◆ PCG32I() [1/2]

PCG32I::PCG32I ( )
inline

Definition at line 97 of file pcg.h.

97: x(), key() { seed(0x46b56677u, 2891336453u); }

◆ PCG32I() [2/2]

PCG32I::PCG32I ( const unsigned s,
const unsigned ss = 2891336453u )
inline

Definition at line 98 of file pcg.h.

98: x(), key() { seed(s, ss); }

Member Function Documentation

◆ seed()

void PCG32I::seed ( const unsigned s,
const unsigned ss )
inline

Definition at line 100 of file pcg.h.

101 {
102 key= (ss << 1) | 1;
103 x= s + key;
104 sample();
105 }

◆ sample()

unsigned PCG32I::sample ( )
inline

Definition at line 109 of file pcg.h.

110 {
111 unsigned xx= x;
112 x= x * 747796405u + key;
113
114 unsigned tmp= ((x >> ((x >> 28u) + 4u)) ^ x) * 277803737u;
115 return (tmp >> 22u) ^ tmp;
116 }

◆ sample_range()

unsigned PCG32I::sample_range ( const unsigned range)
inline

Definition at line 118 of file pcg.h.

119 {
120 // Efficiently Generating a Number in a Range
121 // cf http://www.pcg-random.org/posts/bounded-rands.html
122 unsigned divisor= ((-range) / range) + 1; // (2^32) / range
123 if(divisor == 0) return 0;
124
125 while(true)
126 {
127 unsigned x= sample() / divisor;
128 if(x < range) return x;
129 }
130 }

◆ operator()()

unsigned PCG32I::operator() ( )
inline

Definition at line 133 of file pcg.h.

133{ return sample(); }

◆ min()

constexpr unsigned PCG32I::min ( )
inlinestaticconstexpr

Definition at line 134 of file pcg.h.

134{ return 0; }

◆ max()

constexpr unsigned PCG32I::max ( )
inlinestaticconstexpr

Definition at line 135 of file pcg.h.

135{ return ~unsigned(0); }

Member Data Documentation

◆ x

unsigned PCG32I::x

Definition at line 138 of file pcg.h.

◆ key

unsigned PCG32I::key

Definition at line 139 of file pcg.h.


The documentation for this struct was generated from the following file: