Eightomic PRNG 16 A: The Fastest 16-Bit, Sequential PRNG Versus JSF16, PCG16 and Xorshift16 "798"
Eightomic PRNG 16 A is a 16-bit pseudorandom number generator algorithm that's compatible with 16-bit processors and beyond as a substantial improvement to JSF16, PCG16 and Xorshift16 "798".
Library
Source
#ifndef EIGHTOMIC_PRNG_16_A_H
#define EIGHTOMIC_PRNG_16_A_H
#include <stdint.h>
struct eightomic_prng_16_a_s {
uint16_t a;
uint16_t b;
uint16_t c;
uint16_t d;
uint16_t e;
};
uint16_t eightomic_prng_16_a(struct eightomic_prng_16_a_s *s);
#endif
#include "eightomic_prng_16_a.h"
uint16_t eightomic_prng_16_a(struct eightomic_prng_16_a_s *s) {
s->a += s->d;
s->b = ((s->b << 6) | (s->b >> 10)) + s->c;
s->c += s->e;
s->d = s->b;
s->e -= s->a + 1;
return s->c;
}
Reference
eightomic_prng_16_a() is the randomization function that accepts the following argument.
1: s is the struct eightomic_prng_16_a_s pointer with 4 16-bit unsigned integers s->a, s->b, s->c, s->d and s->e. 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 "eightomic_prng_16_a.h"
int main(void) {
struct eightomic_prng_16_a_s s = {
.a = 0,
.b = 0,
.c = 0,
.d = 0,
.e = 0
};
unsigned char i = 0;
while (i < 10) {
i++;
printf("Result %u is %u.\n", i, eightomic_prng_16_a(&s));
}
return 0;
}
Explanation
It's currently in development and the full explanation is coming soon.
When a cycle of trillions of pseudorandom numbers isn't required on a 32-bit or 64-bit processor, Eightomic PRNG 16 B is a faster alternative with a cycle of 8-16 million high-quality, pseudorandom 16-bit numbers.