# rng.c -rw-r--r-- 633 bytes View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

static int32_t seed;
static void rng() {
	seed = seed * 1103515245 + 12345;
}

static int32_t parse(const char *p) {
	int base = p[0] == '0' && p[1] == 'x' ? 16 : 10;
	return strtol(p, NULL, base);
}

int main(int argc, char **argv)
{
	if (argc < 3) {
		fprintf(stderr, "Usage: %s start end\n", argv[0]);
		return 1;
	}
	int32_t start = parse(argv[1]);
	int32_t end = parse(argv[2]);
	printf("Calculating RNG count between seeds %d and %d...\n", start, end);

	seed = start;
	uint32_t i;
	for (i=0; seed != end; i++) {
		rng();
	}
	printf("Result = %u\n", i);
	return 0;
}