Created
August 12, 2021 05:56
-
-
Save catfact/7b0b5c2aed51a72c36bab72be49ffb60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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