Skip to content

Commit

Permalink
Added pcg32_random_r() inline function to 3DWorld.h for future use (e…
Browse files Browse the repository at this point in the history
…xperimental)
  • Loading branch information
fegennari committed Jun 23, 2019
1 parent d6e1d64 commit 1ce184d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/3DWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,20 @@ class rgen_core_t {
double randd();
};

// *Really* minimal PCG32 code / (c) 2014 M.E. O'Neill / pcg-random.org
// Licensed under Apache License 2.0 (NO WARRANTY, etc. see website)
typedef struct { uint64_t state; uint64_t inc; } pcg32_random_t;

inline uint32_t pcg32_random_r(pcg32_random_t* rng) {
uint64_t oldstate = rng->state;
// Advance internal state
rng->state = oldstate * 6364136223846793005ULL + (rng->inc|1);
// Calculate output function (XSH RR), uses old state for max ILP
uint32_t xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u;
uint32_t rot = oldstate >> 59u;
return (xorshifted >> rot) | (xorshifted << ((-(int32_t)rot) & 31));
}

class rgen_pregen_t : public rgen_core_t {

std::shared_ptr<vector<double>> pregen_rand_reals;
Expand Down

0 comments on commit 1ce184d

Please sign in to comment.