WSP-PRNG-32: The Fastest One-at-a-Time 32-Bit PRNG With Good Quality
WSP-PRNG-32 is a 32-bit pseudorandom number generator algorithm as a substantial improvement to JSF32, Lehmer, PCG32, Xoroshiro and Xorshift32.
Library
Source
Reference
wsp_prng_32_randomize() is the randomization function that accepts the following argument.
1: s is the struct wsp_prng_32_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 "wsp_prng_32.h"
int main(void) {
struct wsp_prng_32_s s = {
.a = 0,
.b = 0,
.increment = 0
};
unsigned char i = 0;
while (i != 10) {
i++;
printf("Result %u is %u.\n", i, wsp_prng_32_randomize(&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.
Explanation
WSP-PRNG-32 is designed to pass statistical tests with efficient resource usage, fast speed and a decent period relative to non-cryptographic, one-at-a-time PRNGs 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.
Compared to PCG32 using pcg32_fast, the average speed is 18% faster.
Furthermore, PCG32 has a smaller full cycle with multiplication operations. Nevertheless, PCG32 may be a reasonable alternative in some applications where statistical randomness evidence is critical.
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, WSP-PRNG-16 is the fastest 16-bit one-at-a-time PRNG with good quality.
When a larger period is required for 32-bit numbers, WSP-Vortex is a high-quality, long-period PRNG with flexible state sizes and similar speed to Xorshift32.
All speed tests are performed locally by generating 1 billion numbers on a Pixelbook Go M3 using Debian.