💾 Archived View for thrig.me › blog › 2024 › 02 › 18 › lrngsmol-32-7.c captured on 2024-07-09 at 03:18:25.

View Raw

More Information

⬅️ Previous capture (2024-03-21)

-=-=-=-=-=-=-

// a smol Lehmer random number generator

#include <stdint.h>
#include <stdio.h>

uint8_t
lrngsmol(uint8_t *state, uint8_t m, uint8_t a)
{
	return *state = (uint16_t) *state * a % m;
}

int
main(void)
{
	for (uint8_t seed = 0; seed < 32; seed++) {
		printf("seed %u -", seed);
		uint8_t state = seed;
		for (size_t i = 0; i < 8; ++i) {
			printf(" %u", lrngsmol(&state, 32, 7));
		}
		putchar('\n');
	}
}