Skip to content

Instantly share code, notes, and snippets.

@catfact
Created August 12, 2021 05:56
Show Gist options
  • Select an option

  • Save catfact/7b0b5c2aed51a72c36bab72be49ffb60 to your computer and use it in GitHub Desktop.

Select an option

Save catfact/7b0b5c2aed51a72c36bab72be49ffb60 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdint.h>
struct state {
uint16_t x;
uint16_t y;
uint16_t z;
};
// multipliers and modulos
struct config {
uint16_t cx;
uint16_t mx;
uint16_t cy;
uint16_t my;
uint16_t cz;
uint16_t mz;
};
static const struct config conf = {
157, 32363,
146, 31727,
142, 31657
};
static uint16_t update(struct state *s, const struct config *c) {
s->x = (s->x * c->cx) % c->mx;
s->y = (s->y * c->cy) % c->my;
s->z = (s->z * c->cz) % c->mz;
return (s->x - s->y + s->z) % 32362;
}
int main()
{
// seed values aren't important, but zeros are to be avoided
struct state s = {
0xdead, 0xbeef, 0xcafe
};
uint64_t n;
n = (uint64_t)1e7;
for (uint64_t i=0; i<n; ++i) {
printf("%d\n", update(&s, &conf));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment