summaryrefslogtreecommitdiff
path: root/lib/igt_rand.c
blob: b8d3a92cf79f7885d3a3204164dc631ab3ecf9dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "igt_rand.h"

static uint32_t global = 0x12345678;

uint32_t hars_petruska_f54_1_random_seed(uint32_t new_state)
{
	uint32_t old_state = global;
	global = new_state;
	return old_state;
}

uint32_t hars_petruska_f54_1_random(uint32_t *s)
{
#define rol(x,k) ((x << k) | (x >> (32-k)))
	return *s = (*s ^ rol(*s, 5) ^ rol(*s, 24)) + 0x37798849;
#undef rol
}

uint32_t hars_petruska_f54_1_random_unsafe(void)
{
	return hars_petruska_f54_1_random(&global);
}