From 62a1f544fcbb264b8b70d25ed9fb7395e109160a Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 9 May 2017 12:42:41 +0100 Subject: wsim: Per-client prng pool for miscellaneous randoms Signed-off-by: Chris Wilson --- lib/igt_rand.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'lib/igt_rand.c') diff --git a/lib/igt_rand.c b/lib/igt_rand.c index a3298a9f..b8d3a92c 100644 --- a/lib/igt_rand.c +++ b/lib/igt_rand.c @@ -1,19 +1,22 @@ #include "igt_rand.h" -static uint32_t state = 0x12345678; +static uint32_t global = 0x12345678; -uint32_t -hars_petruska_f54_1_random_seed(uint32_t new_state) +uint32_t hars_petruska_f54_1_random_seed(uint32_t new_state) { - uint32_t old_state = state; - state = new_state; + uint32_t old_state = global; + global = new_state; return old_state; } -uint32_t -hars_petruska_f54_1_random_unsafe(void) +uint32_t hars_petruska_f54_1_random(uint32_t *s) { #define rol(x,k) ((x << k) | (x >> (32-k))) - return state = (state ^ rol (state, 5) ^ rol (state, 24)) + 0x37798849; + 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); +} -- cgit v1.2.3