Eightomic

Eightomic PRNG 16 B: The Fastest 16-Bit, Sequential PRNG Versus Slow, Weak Generators

Eightomic PRNG 16 B is a 16-bit pseudorandom number generator algorithm as a substantial improvement to rand() from stdlib.h and other slow, weak PRNGs.

Library

Source

#ifndef EIGHTOMIC_PRNG_16_B_H #define EIGHTOMIC_PRNG_16_B_H #include <stdint.h> struct eightomic_prng_16_b_s { uint32_t a; uint32_t b; }; uint16_t eightomic_prng_16_b(struct eightomic_prng_16_b_s *s); #endif#include "eightomic_prng_16_b.h" uint16_t eightomic_prng_16_b(struct eightomic_prng_16_b_s *s) { s->a = ((s->a << 13) | (s->a >> 19)) ^ s->b; s->b += 1111111; return s->a; }

Reference

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

1: s is the struct eightomic_prng_16_b_s pointer with 2 32-bit unsigned integers s->a and s->b. Each must be initialized with any combination of values including 0.

The return value data type is uint16_t.

It returns the 16-bit unsigned integer pseudorandom number result.

Example

#include <stdio.h> #include "eightomic_prng_16_b.h" int main(void) { struct eightomic_prng_16_b_s s = { .a = 0, .b = 0 }; unsigned char i = 0; while (i < 10) { i++; printf("Result %u is %u.\n", i, eightomic_prng_16_b(&s)); } return 0; }

Explanation

Eightomic PRNG 16 B passes stdin16 PractRand tests up to 16 million randomized 16-bit numbers.

It's faster than the lower 16 bits of Eightomic PRNG 32 A.

It's faster than rand() in standard C implementations.

Furthermore, rand() passes PractRand tests up to 512000 randomized numbers, which is 7% of the high-quality randomized numbers that Eightomic PRNG 16 B generates.

It's faster than PCG16 using pcg16_fast.

It's faster than JSF16.

Although PCG16 passes PractRand tests up to 512 million randomized 16-bit numbers, truncated Eightomic PRNG 32 A passes beyond 32 billion randomized 16-bit numbers with substantially-better diffusion and faster speed as a better option than PCG16 only when mathematical randomness evidence is critical.

It's faster than all Xoroshiro and Xorshift algorithms, including Xorshift16 "798".

Furthermore, Xorshift16 "798" passes PractRand tests up to 64000 randomized numbers, which is less than 1% of the high-quality randomized numbers that Eightomic PRNG 16 B generates.

Furthermore, some of the compared PRNGs are vulnerable to several confirmed broken cycles when seeded with specific values, including 0.

Eightomic created a small web browser game that demonstrates fast performance and satisfactory 16-bit randomness with a JavaScript variation of Eightomic PRNG 16 B.

All speed tests generate and access 1 billion numbers.