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

static uint32_t state = 0x12345678;

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

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