igt_rand.c 587 Bytes
Newer Older
1 2
#include "igt_rand.h"

3 4 5 6 7 8 9
/**
 * SECTION:igt_rand
 * @short_description: Random numbers helper library
 * @title: Random
 * @include: igt_rand.h
 */

10
static uint32_t global = 0x12345678;
11

12
uint32_t hars_petruska_f54_1_random_seed(uint32_t new_state)
13
{
14 15
	uint32_t old_state = global;
	global = new_state;
16 17 18
	return old_state;
}

19
uint32_t hars_petruska_f54_1_random(uint32_t *s)
20 21
{
#define rol(x,k) ((x << k) | (x >> (32-k)))
22
	return *s = (*s ^ rol(*s, 5) ^ rol(*s, 24)) + 0x37798849;
23 24
#undef rol
}
25 26 27 28 29

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