Eightomic PRNG 8: The Fastest 8-Bit, Sequential PRNG Versus JSF8 and PCG8
Eightomic PRNG 8 is an 8-bit pseudorandom number generator algorithm that's compatible with 8-bit processors and beyond as a substantial improvement to JSF8 and PCG8.
Library
Source
#ifndef EIGHTOMIC_PRNG_8_H
#define EIGHTOMIC_PRNG_8_H
#include <stdint.h>
struct eightomic_prng_8_s {
uint8_t a;
uint8_t b;
uint8_t c;
uint8_t d;
uint8_t e;
};
uint8_t eightomic_prng_8(struct eightomic_prng_8_s *s);
#endif
#include "eightomic_prng_8.h"
uint8_t eightomic_prng_8(struct eightomic_prng_8_s *s) {
s->a += s->d;
s->b = ((s->b << 3) | (s->b >> 5)) + s->c;
s->c += s->e | 1;
s->d = s->b;
s->e += s->a;
return s->e;
}
Reference
eightomic_prng_8() is the randomization function that accepts the following argument.
1: s is the struct eightomic_prng_8_s pointer with 4 8-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 uint8_t.
It returns the 8-bit unsigned integer pseudorandom number result.
Example
#include <stdio.h>
#include "eightomic_prng_8.h"
int main(void) {
struct eightomic_prng_8_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_8(&s));
}
return 0;
}
Explanation
The full explanation is coming soon.