WSP-PRNG-16: The Fastest 16-Bit PRNG With Good Quality
WSP-PRNG-16 is a 16-bit pseudorandom number generator algorithm as a substantial improvement to standard library rand() functions, PCG16 and Xorshift16 "798".
Library
Source
Reference
wsp_prng_16_randomize() is the randomization function that accepts the following argument.
1: s is the struct wsp_prng_16_s pointer with 2 32-bit unsigned integers s->increment and s->increment_offset. Each must be initialized with any combination of values.
The return value data type is uint16_t.
It returns the 16-bit unsigned integer pseudorandom number result.
Example
#include <stdio.h>
#include "wsp_prng_16.h"
int main(void) {
struct wsp_prng_16_s s = {
.increment = 0,
.increment_offset = 0
};
unsigned char i = 0;
while (i != 10) {
i++;
printf("Result %u is %u.\n", i, wsp_prng_16_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-16 is designed to use as an improvement to non-cryptographic, one-at-a-time PRNGs that generate a large amount of small numbers 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.
16-bit deterministic randomness is generated with a 64-bit state.
By default, the period guarantees a smallest full cycle of 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.
It passes stdin16 PractRand tests up to 32 MB or 4 million randomized numbers.
Compared to rand() in a local C99 implementation, it's 1000% faster with better statistical quality. rand() passes PractRand tests up to 512 KB or 256,000 randomized numbers, which is 7% of the quality random numbers WSP-PRNG-16 generates.
Compared to PCG16, it's at least 150% faster. PCG16 passes PractRand tests up to 250 million randomized 16-bit numbers and may be a reasonable alternative in some applications where statistical randomness evidence is critical.
Compared to all Xoroshiro and Xorshift algorithms, including Xorshift16 "798", it's 45% to 65% faster. Xorshift16 "798" passes PractRand tests up to 64 KB or 32,000 randomized numbers, which is less than 1% of the quality random numbers WSP-PRNG-16 generates.
Furthermore, some of these PRNGs are vulnerable to several confirmed broken cycles when seeded with specific values, including 0.
Compared to the lower 16 bits of WSP-PRNG-32, it's 30% faster.
All speed tests are performed locally by generating 1 billion numbers on a Pixelbook Go M3 using Debian.