
PRNG 32 B
It's the fastest 32-bit, sequential PRNG versus all 32-bit, sequential PRNGs that pass BigCrush.
Algorithm
Source
#include <stdint.h>
struct eightomic_prng_32_b_s {
uint32_t a;
uint32_t b;
uint32_t c;
uint32_t d;
uint32_t e;
};
uint32_t eightomic_prng_32_b(struct eightomic_prng_32_b_s *s) {
s->a += s->e;
s->b = ((s->b << 19) | (s->b >> 13)) ^ s->d;
s->c -= 111111;
s->d -= s->c;
s->e += s->b;
return s->a;
}
License
It's free and open source.
Reference
eightomic_prng_32_b() is the randomization function that accepts the following argument.
1: s is the struct eightomic_prng_32_b_s pointer with 5 uint32_t integers s->a, s->b, s->c, s->d and s->e. Each must be initialized with any combination of values.
The return value data type is uint32_t.
It returns the 32-bit unsigned integer pseudorandom number result.
Explanation
It's the fastest deterministic, sequential PRNG that passes TestU01 BigCrush tests.
It has an estimated full cycle of between 2⁶⁴ and 2⁹⁶ numbers.
Furthermore, it guarantees a minimum cycle of 2³² numbers by subtracting an odd-numbered constant from s->c, then subtracting the result from s->d for 2³² different numbers to XOR with s->b.
s->d eventually cycles through all 2³² numbers with an overlap of mixed duplicate numbers to offset the less-random distribution of s->c.
The additive assignments for s->a and s->e have similar cyclic properties, resulting in a conservative total full cycle estimation of between 2⁶⁴ and 2⁹⁶ numbers returned from s->a.
The following cycle demonstration proves the aforementioned security concept with only 2⁸ numbers for computational feasibility.
#include <stdint.h>
#include <stdio.h>
struct eightomic_cycle_s {
uint8_t a;
uint8_t b;
uint8_t c;
};
void eightomic_cycle(struct eightomic_cycle_s *s) {
s->a -= s->c;
s->b -= s->a;
}
int main(void) {
struct eightomic_cycle_s s;
unsigned char captures[256];
uint16_t captures_count;
uint32_t broken_cycles_count = 0;
uint16_t i;
uint16_t j;
uint16_t k;
unsigned char has_cycled = 0;
s.c = 1;
while (
s.c != 1 ||
has_cycled == 0
) {
i = 0;
while (i < 256) {
j = 0;
while (j < 256) {
k = 0;
while (k < 256) {
captures[k] = 0;
k++;
}
s.a = i;
s.b = j;
captures[s.b] = 1;
eightomic_cycle(&s);
k = 0;
while (k < 512) {
captures[s.b] = 1;
eightomic_cycle(&s);
k++;
}
captures_count = 0;
k = 0;
while (k < 256) {
captures_count += captures[k];
k++;
}
if (captures_count != 256) {
broken_cycles_count++;
}
j++;
}
i++;
}
s.c += 2;
has_cycled = 1;
}
if (broken_cycles_count == 0) {
printf("eightomic_cycle() cycles through all 2⁸ numbers in s->b.\n");
}
return 0;
}
The following test results are performed with all state bits initialized to 0.
It passes BigCrush and Diehard tests. PractRand test results are pending.
It's compared to the fastest 32-bit PRNGs that generate one random number per function call as required in most practical instances.
It's faster than all 32-bit variations of Xoroshiro, Xoshiro and Xorshift.
It's faster than JSF32, Lehmer and PCG32 using pcg32_fast.
Furthermore, most of these PRNGs are vulnerable to several confirmed broken cycles when seeded with specific values, including 0.
When only 16-bit numbers are required, Eightomic PRNG 16 B is faster with good diffusion and a large full cycle.
When a longer full cycle is required for 32-bit numbers, Eightomic PRNG 32 C is a high-quality, long-period PRNG with flexible state sizes and similar speed to Xorshift32.