Repository navigation
Expand file tree
/
Copy pathpcg64_64.c
More file actions
48 lines (43 loc) · 1.49 KB
/
Copy pathpcg64_64.c
File metadata and controls
48 lines (43 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* @file pcg64_64.c
* @brief PCG64 PRNG implementation with RXS-M-XS64 function.
* @details PCG (permuted congruental generators) is a family of pseudorandom
* number generators invented by M.E. O'Neill. This version has 64-bit state
* and 64-bit output and its period is \f$2^{64}\f$. It passes almost all
* batteries from SmokeRand test suite except `birthday` battery that detects
* absence of repeats in the output.
*
* PCG64 with RXS-M-XS64 output function also passes SmallCrush, Crush and
* BigCrush batteries from TestU01.
*
* @copyright The PCG algorithm family is suggested by M.E. O'Neill
* (https://pcg-random.org).
*
* Implementation for SmokeRand:
*
* (c) 2024-2026 Alexey L. Voskov, Lomonosov Moscow State University.
* alvoskov@gmail.com
*
* This software is licensed under the MIT license.
*/
#include "smokerand/cinterface.h"
PRNG_CMODULE_PROLOG
typedef struct {
uint64_t state; ///< LCG state
uint64_t inc; ///< LCG increment, must be odd
} Pcg64State;
static inline uint64_t get_bits_raw(Pcg64State *obj)
{
const uint64_t word = ((obj->state >> ((obj->state >> 59) + 5)) ^ obj->state) *
12605985483714917081ull;
obj->state = obj->state * 6364136223846793005ull + obj->inc;
return (word >> 43) ^ word;
}
static void *create(const CallerAPI *intf)
{
Pcg64State *obj = intf->malloc(sizeof(Pcg64State));
obj->state = intf->get_seed64();
obj->inc = intf->get_seed64() | 1; // Odd increment
return obj;
}
MAKE_UINT64_PRNG("PCG64", NULL)