Eightomic Icon Eightomic

32-Bit Pseudorandom Number Generator: A High-Performance, Low-Resource and Portable Approach With Provable Statistical Quality

Eightomic developed a free 32-bit pseudorandom number generator algorithm in C99 as a marginal improvement to JSF32 and PCG32.

Algorithm

#include <stdint.h> static uint32_t state[3]; void eightomic_prng_32_initialize(uint32_t *state) { state[0] += state[2] + 1111111111; state[1] += state[0] + 1111111111; state[2] += state[1] + 1111111111; state[0] += state[1] ^ state[2]; state[0] = (((state[0] << 14) | (state[0] >> 18)) ^ state[1]) + 1111111111; state[2] += 1111111111; state[1] = ((state[1] << 21) | (state[1] >> 11)) + state[2]; state[0] = (((state[0] << 14) | (state[0] >> 18)) ^ state[1]) + 1111111111; state[2] += 1111111111; state[1] = ((state[1] << 21) | (state[1] >> 11)) + state[2]; } uint32_t eightomic_prng_32_randomize(uint32_t *state) { state[0] = ((state[0] << 14) | (state[0] >> 18)) ^ state[1]; state[2] += 1111111111; state[1] = ((state[1] << 21) | (state[1] >> 11)) + state[2]; return state[0] + 1111111111; }

Reference

eightomic_prng_32_initialize() is the initialization function that accepts the following argument.

state is an array with 3 32-bit unsigned integers initialized with any value.

The return value data type is void.

eightomic_prng_32_randomize() is the randomization function that accepts the following argument.

state is an array with 3 32-bit unsigned integers initialized with any value.

The return value data type is uint32_t.

It returns the 32-bit unsigned integer pseudorandom number result from state[0].

Explanation

This 32-bit PRNG is designed to pass statistical tests with efficient resource usage and a decent period.

It's portable for both 32-bit and 64-bit systems.

It doesn’t use modulus, multiplication or division arithmetic operations.

32-bit entropy is generated with a 96-bit auxiliary state.

By default, the period guarantees a smallest full cycle of 2^32 numbers, an estimated average full cycle of 2^64 and a largest full cycle of 2^96 numbers.

The first 32 bits of state are summed with 1111111111 after each random number generation result and mixed in with the bit shuffling sequence.

This minimizes the probability of broken infinite cycles and makes it trivial to add an occasional increment for estimated, randomized jumps.

Furthermore, when all state bits are 0, the next pseudorandom number escapes zeroland quickly, making it impossible to have a broken state with any combination of numbers.

The following code example generates randomized output.

#include <stdint.h> #include <stdio.h> uint32_t eightomic_prng_32_randomize(uint32_t *state) { state[0] = ((state[0] << 14) | (state[0] >> 18)) ^ state[1]; state[2] += 1111111111; state[1] = ((state[1] << 21) | (state[1] >> 11)) + state[2]; return state[0] + 1111111111; } int main(void) { uint32_t state[3] = {0, 0, 0}; uint32_t entropy = eightomic_prng_32_randomize(state); while (1) { fwrite(&entropy, sizeof(uint32_t), 1, stdout); entropy = eightomic_prng_32_randomize(state); } return 0; }

It passes all Diehard tests and extended Dieharder tests.

It passes all BigCrush battery tests.

It passes all 26 PractRand tests up to the default maximum of 32 TB using the same bits from the aforementioned DieHard tests.

Compared to PCG32, the average speed is marginally-faster by about 20ms on AMD CPUs and 10% faster on Intel CPUs when generating 1 billion random numbers repeatedly.

Furthermore, PCG32 has a smaller full cycle with a stricter 64-bit system requirement and multiplication operations.

Compared to JSF32, the average speed is 20% faster when generating 1 billion random numbers repeatedly.

Furthermore, JSF32 has several confirmed broken cycles.

All speed tests were performed locally on a Pixelbook Go Intel M3 and a Lenovo Chromebook AMD A4–9120C Radeon R4.

Requirements

  • C compiler with C99 (ISO/IEC 9899:1999) standard compatibility.
  • CPU with single-threaded, instruction-level parallelism support.

Consulting

Send a message containing an introduction to your specification for development and let Eightomic evolve your proprietary product with a custom-tailored, next-level solution.

Sponsor

Eightomic is supported by GhostProxies, a free open proxy IP address history lookup service with a paid API to help block cyber attacks and reduce fraud with less false positives.

Libraries

QuakeShift QuakeShift Icon

Character Encoding Conversion Library

Validate and transcode displayable text data using standards-compliant conversion algorithms with common character encoding formats.

->
StormDrop StormDrop Icon

Complex Pattern Recognition Library

Scan arbitrary data sequences with deterministic algorithms to analyze and detect advanced pattern occurrences.

->
Random Number Generation Library VortexSpin VortexSpin Icon

Random Number Generation Library

Spawn quantum entropy with a TRNG algorithm using a scientifically-proven combination of quantum mechanics and temporal precision.

->