WSP-PRNG-32: A High-Performance, Low-Resource, Non-Multiplicative 32-Bit PRNG With Good Statistical Quality and a Large Full Cycle
William Stafford Parsons developed a 32-bit pseudorandom number generator algorithm as a substantial improvement to JSF32, Lehmer, PCG32, Xoroshiro and Xorshift32.
Library
Source
#include <stdint.h>
struct wsp_prng_32_s {
uint32_t a;
uint32_t b;
uint32_t increment;
};
uint32_t wsp_prng_32_randomize(struct wsp_prng_32_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
wsp_prng_32_randomize() is the randomization function that accepts the following argument.
s is a struct wsp_prng_32_s pointer with 3 32-bit unsigned integers s->a, s->b and s->increment, each initialized with any seed values.
The return value data type is uint32_t.
It returns the 32-bit unsigned integer pseudorandom number result.
Requirements
C compiler with C99 (ISO/IEC 9899:1999) standard compatibility.
CPU with single-threaded, instruction-level parallelism support.
Explanation
WSP-PRNG-32 is designed to pass statistical tests with efficient resource usage, fast speed and a decent period.
It's portable for both 32-bit and 64-bit systems.
It meets strict compliance, portability and code security requirements, although it's a PRNG that isn't suitable for cryptographic purposes.
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.
This linear increment eliminates the probability of broken infinite cycles when combined with s->a and s->b and makes it trivial to add an occasional increment externally 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 test results were 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. As speculated by the creators of Xoroshiro, 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 statistical 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 can fail these statistical tests badly after only a few MB.
Compared to PCG32, the average speed is 8% to 10% faster.
Compared to pcg32_fast, the average speed is similar, but when compiler optimization is enabled with -O3, the average speed is at least 18% faster.
Furthermore, PCG32 has a smaller full cycle with a stricter 64-bit system requirement and 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.
If only 16-bit numbers are required, WSP-PRNG-16 is the fastest 16-bit one-at-a-time PRNG with good statistical quality results.
If 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 were performed locally by generating 1 billion numbers on a Pixelbook Go M3 using Debian.
Games
Contrivity
Spawn into the hostile quantum laboratory and destroy wave after wave of oscillations.