Eightomic PRNG 32 A: The Fastest 32-Bit, Sequential PRNG Versus JSF32, PCG32 and Xorshift32
Eightomic PRNG 32 A is a 32-bit, short-period pseudorandom number generator algorithm as a substantial improvement to JSF32, Lehmer, PCG32, Xoroshiro and Xorshift32.
Library
Source
#ifndef EIGHTOMIC_PRNG_32_A_H
#define EIGHTOMIC_PRNG_32_A_H
#include <stdint.h>
struct eightomic_prng_32_a_s {
uint32_t a;
uint32_t b;
uint32_t c;
uint32_t d;
};
uint32_t eightomic_prng_32_a(struct eightomic_prng_32_a_s *s);
#endif
#include "eightomic_prng_32_a.h"
uint32_t eightomic_prng_32_a(struct eightomic_prng_32_a_s *s) {
s->a = ((s->a << 11) | (s->a >> 21)) ^ s->d;
s->b = ((s->b << 19) | (s->b >> 13)) + s->c;
s->c = 1111111111 - s->c;
s->d -= s->b;
return s->a;
}
Reference
eightomic_prng_32_a() is the randomization function that accepts the following argument.
1: s is the struct eightomic_prng_32_a_s pointer with 4 uint32_t integers s->a, s->b, s->c and s->d. 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.
Example
#include <stdio.h>
#include "eightomic_prng_32_a.h"
int main(void) {
struct eightomic_prng_32_a_s s = {
.a = 0,
.b = 0,
.c = 0,
.d = 0
};
unsigned char i = 0;
while (i < 10) {
i++;
printf("Result %u is %u.\n", i, eightomic_prng_32_a(&s));
}
return 0;
}
Explanation
Eightomic PRNG 32 A has an estimated average full cycle between 2⁶⁴ and 2¹²⁸ numbers.
The following test results are performed with all state bits initialized to 0.
It passes Diehard tests.
It's likely to pass Practrand tests beyond the default 32 TB limit, but they waste excessive electricity for 2 weeks and Eightomic can't afford the utility bill overage.
It passes all TestU01 BigCrush tests as the fastest one-at-a-time PRNG that passes BigCrush.
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 JSF32.
It's faster than PCG32 using pcg32_fast.
It's faster than Lehmer.
It's faster than all Xoroshiro and Xorshift algorithms.
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 the fastest 16-bit PRNG with good diffusion.
When a longer full cycle is required for 32-bit numbers, Eightomic PRNG 32 B is a high-quality, long-period PRNG with flexible state sizes and similar speed to Xorshift32.
All speed tests generate and access 1 billion numbers.