GhostProxies

GhostProxies PRNG 32 A: The Fastest 32-Bit, Sequential PRNG That Obsoletes PCG32 and Xorshift32

GhostProxies 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 GHOSTPROXIES_PRNG_32_A_H #define GHOSTPROXIES_PRNG_32_A_H #include <stdint.h> struct ghostproxies_prng_32_a_s { uint32_t a; uint32_t b; uint32_t increment; }; uint32_t ghostproxies_prng_32_a(struct ghostproxies_prng_32_a_s *s); #endif#include "ghostproxies_prng_32_a.h" uint32_t ghostproxies_prng_32_a(struct ghostproxies_prng_32_a_s *s) { s->a = ((s->a << 14) | (s->a >> 18)) ^ s->b; s->increment += 1111111111; s->b = ((s->b << 21) | (s->b >> 11)) + s->increment; return s->a + 1111111111; }

Reference

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

1: s is the struct ghostproxies_prng_32_a_s pointer with 3 uint32_t integers s->a, s->b and s->increment. 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 "ghostproxies_prng_32_a.h" int main(void) { struct ghostproxies_prng_32_a_s s = { .a = 0, .b = 0, .increment = 0 }; unsigned char i = 0; while (i != 10) { i++; printf("Result %u is %u.\n", i, ghostproxies_prng_32_a(&s)); } return 0; }

Requirements

It adheres to the C99 standard draft (ISO/IEC 9899:1999), although it's convertible to other programming languages and standards.

License

GhostProxies PRNG 32 A usage is subject to proprietary Skeleton Key licensing restrictions.

Evaluation is permitted for a reasonable, short period of time.

Explanation

GhostProxies PRNG 32 A passes statistical tests with efficient resource usage, fast speed and a decent period relative to non-cryptographic PRNGs that access each generated result immediately in high-performance applications.

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

It meets strict compliance, portability and code security requirements.

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

32-bit deterministic randomness is generated with a 96-bit auxiliary state.

By default, the period guarantees a smallest full cycle of 2³² numbers and an estimated average full cycle between 2⁶⁴ and 2⁹⁶ numbers.

32 bits of state in s->increment are summed with 1111111111 after each random number generation result and mixed in with the bit shuffling sequence to eliminate the probability of broken states with any combination of numbers.

The following test results are performed with all state bits initialized to 0.

It passes all TestU01 BigCrush battery tests as the fastest one-at-a-time PRNG that passes BigCrush.

It passes Diehard battery tests.

It passes stdin32 PractRand battery tests up until the default limit of 32 TB, which is far beyond the default practical limit of 5 TB. Anything beyond the aforementioned practical limit doesn't affect any application in which the evidence of statistical quality itself isn't a strict requirement.

The 32 TB PractRand test only failed 1 of about 100 tests when seeded with 0, suggesting the seed values caused an anomalic positive that could easily occur in a source of true randomness. Furthermore, true-random number generators often fail the aforementioned tests after only a few MB.

It's compared to the fastest 32-bit PRNGs that generate one random number per function call as required in most practical instances.

Compared to PCG32 using pcg32_fast, the average speed is 18% faster.

Furthermore, PCG32 has a shorter full cycle with multiplication operations. When mathematical randomness evidence is critical to correlate more than 32 TB of randomized numbers, GhostProxies PRNG 32 B is a better alternative.

Compared to JSF32 and Lehmer, the average speed is 20% faster.

Compared to all Xoroshiro and Xorshift algorithms, it's 20% to 40% faster.

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, GhostProxies PRNG 16 is the fastest 16-bit PRNG with good diffusion.

When a larger period is required for 32-bit numbers, GhostProxies 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.