
PRNG C 32
It's a fast, statistically-strong PRNG with 32-bit integers and a period of 2³⁴ to 2⁶⁴.
Algorithm
Source
#include <stdint.h>
struct eightomic_prng_c_32_s {
uint32_t a;
uint32_t b;
uint32_t c;
};
uint32_t eightomic_prng_c_32(struct eightomic_prng_c_32_s *s) {
uint32_t block = s->a + s->c;
s->a = ((s->a << 17) | (s->a >> 15)) ^ s->b;
s->b += 1111111111;
s->c = (block << 13) | (block >> 19);
return block;
}
License
It's free and open source with permitted usage subject to the following condition.
The function name eightomic_prng_c_32() must not change.
Reference
eightomic_prng_c_32() is the randomization function that accepts the following argument.
1: s is the struct eightomic_prng_c_32_s pointer with 3 uint32_t integers s->a, s->b and s->c. Each must be initialized with any combination of values.
The return value data type is uint32_t.
It returns a 32-bit unsigned integer pseudorandom number result.
Period
It has an approximated maximum period of between 2³⁴ and 2⁶⁴.
It has a minimum period of 2³⁴.
An odd-numbered constant sums with s->b for 2³² different numbers to XOR with s->a in each cycle.
The minimum period increases from 2³² to 2³⁴ based on the small cycle verification from PRNG C 8.
Incrementing s->b outside of eightomic_prng_c_32() behaves as an interdimensional jump function that starts a different number cycle, resulting in at least 2³² different number cycles.
Speed
It's possibly the fastest 32-bit PRNG that both generates numbers individually and passes extensive statistical tests within a medium period.
Security
There aren't any broken number cycles smaller than the aforementioned proven minimum period of 2³⁴.
Zeroland escapes quickly after generating 3 subsequent numbers.
Randomness
The following code outputs a cycle of 512 pseudorandom numbers from all bits seeded with 0.
#include <stdint.h>
#include <stdio.h>
struct eightomic_prng_c_32_s {
uint32_t a;
uint32_t b;
uint32_t c;
};
uint32_t eightomic_prng_c_32(struct eightomic_prng_c_32_s *s) {
uint32_t block = s->a + s->c;
s->a = ((s->a << 17) | (s->a >> 15)) ^ s->b;
s->b += 1111111111;
s->c = (block << 13) | (block >> 19);
return block;
}
int main(void) {
struct eightomic_prng_c_32_s s = {
.a = 0,
.b = 0,
.c = 0
};
uint16_t i = 0;
printf("%10u", eightomic_prng_c_32(&s));
while (i < 512) {
printf(" %10u", eightomic_prng_c_32(&s));
i++;
if ((i % 6) == 0) {
printf("\n%10u", eightomic_prng_c_32(&s));
}
}
return 0;
}
The following truncated output from the aforementioned code demonstrates strong randomness with visually-acceptable distribution at first glance after escaping zeroland.
0 0 1111111111 917755969 2489558390 1784133686 2004727036
4174893366 1161878299 87466163 4164063487 1226068228 94251911 601969762
3862318199 1516799100 4271084135 2682486858 3577158934 499509323 2921655611
3711125375 916460010 2680572750 3308897259 588281310 2625395116 514982214
1735741659 3463650379 1101781234 4156176715 776599845 4064287849 1749993177
3010796278 2039334260 1188082386 3951370849 200838991 3343572872 16524994
96081640 3002913820 1402044081 3799676577 2335724290 3581158001 252216412
172130821 4256061889 1793464762 1221252954 3139121252 3735583183 1272554146
2876259961 2635490093 2985330531 3080739393 2528469166 2196201300 3406695972
3008188885 3874852689 4047979923 2858440549 2892436321 3414394733 2778944610
1457548412 1108015006 3868478216 791752075 3919283205 2305608069 416981442
2628078434 2759397269 2008172874 2410250764 73258277 749685850 1254564672
2817636170 400914269 1758969319 35016732 298832469 1517262377 3567361459
3765542626 4127760601 1503139485 2742071013 1813492374 1713120814 3914514933
1252615848 898268240 3372147024 1202588788 2280417657 795349742 1759948109
4279157477 3671006262 3090619355 315443795 4284437424 3135007101 1935045289
The distribution properties of the aforementioned interdimensional period are similar to a counter-based RNG that eventually generates 1 of each number in a 2³² range when using interdimensional jumps.
Without interdimensional jumps, each individual 2³⁴ period emulates non-deterministic probability where some numbers may be repeated and some numbers may be missing.