2 ms·
> PCG is incredibly simple as well Yes and no. There are a lot of different functions in the PCG umbrella and that adds some mental complexity IMO. Some of t
by loeg 7y ago
> PCG is incredibly simple as well
Yes and no. There are a lot of different functions in the PCG umbrella and that adds some mental complexity IMO. Some of the functions are very simple, including the 128-bit LCG I am referring to above ("pcg64_fast", IIRC). It is almost trivial; basically a single LoC to generate the next state and a single LoC to produce the output from that state:
https://github.com/imneme/pcg-c/blob/master/include/pcg_variants.h#L2408 https://github.com/imneme/pcg-c/blob/master/include/pcg_vari...
https://github.com/imneme/pcg-c/blob/master/include/pcg_variants.h#L2225-L2228 https://github.com/imneme/pcg-c/blob/master/include/pcg_vari...
https://github.com/imneme/pcg-c/blob/master/include/pcg_variants.h#L618 https://github.com/imneme/pcg-c/blob/master/include/pcg_vari...
https://github.com/imneme/pcg-c/blob/master/include/pcg_variants.h#L243 https://github.com/imneme/pcg-c/blob/master/include/pcg_vari...
Or condensed from several composed inline functions:
uint64_t
my_pcg64_fast(uint128_t *state)
{
// Multiplier: (2549297995355413924ULL << 64) + 4865540595714422341ULL
*state *= PCG_DEFAULT_MULTIPLIER_128;
// Output is XOR-condensed state rotated right by the high 6 bits of state.
return pcg_rotr_64(((uint64_t)(*state >> 64u)) ^ (uint64_t)*state,
*state >> 122u);
}