16-Bit Pseudorandom Number Generator: A Fast, Tiny PRNG With Good Statistical Quality Among Large Quantities of Small Numbers Generated

Eightomic developed a 16-bit pseudorandom number generator algorithm with a library in C99 as a significant performance improvement to standard library rand() functions, Xorshift and other PRNG algorithms, primarily for video game applications that rely on randomized 16-bit numbers.

Library

Source

#include <stdint.h> struct eightomic_s { uint32_t a; uint32_t b; }; void eightomic_randomize(struct eightomic_s *s) { s->a = ((s->a << 13) | (s->a >> 19)) ^ s->b; s->b += 1111111; }

Reference

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

s is a struct eightomic_s pointer with 2 32-bit unsigned integers s->a and s->b initialized with any seed values. s->a contains the randomized number result.

The return value data type is void.

Requirements

C compiler with C99 (ISO/IEC 9899:1999) standard compatibility.

Explanation

This 16-bit PRNG is designed to use as an improvement to PRNGs that generate a large amount of small numbers.

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

It meets strict compliance, portability and security requirements.

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

16-bit entropy is generated with a 64-bit state.

By default, the period guarantees a smallest full cycle of 2^32 numbers.

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

This eliminates 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.

It passes stdin16 PractRand tests up to 32 MB or 4 million randomized numbers without re-seeding the initialized state.

This upper limit is suitable for many applications that need the fastest-possible randomization function for approximate, frequent calculations with small numbers, such as hit or miss calculations, movement direction decisions and recoil oscillations.

After 2 to 4 million numbers are generated, s->a or s->b values can be reassigned with a low-footprint, pseudorandom value from a timestamp or a frequently-changing set of UUIDs.

Compared to rand() in a local C99 implementation, it's 1000% faster with better statistical quality.

Compared to PCG16, it's at least 150% faster, but PCG16 generates 250 million randomized 16-bit numbers without re-seeding.

Compared to all Xoroshiro and Xorshift algorithms, including Xorshift16 "798", it's 45% to 65% faster with better statistical quality.

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 the Eightomic 32-bit PRNG, it's 30% faster, but the Eightomic 32-bit PRNG generates more than 2 billion randomized 16-bit numbers without re-seeding.

Games

Contrivity Contrivity Icon

Contrivity

Spawn into the hostile quantum laboratory and destroy wave after wave of oscillations.

v1.0.14