summaryrefslogtreecommitdiff
path: root/lib/igt_rand.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2017-05-09 12:42:41 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2017-05-09 15:36:54 +0100
commit62a1f544fcbb264b8b70d25ed9fb7395e109160a (patch)
treea9172c1dba2c46bc24d758636f580de587e267b6 /lib/igt_rand.c
parent0d67d8ee678e883ba8a1e40699b73b7db2d540fe (diff)
wsim: Per-client prng pool for miscellaneous randoms
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'lib/igt_rand.c')
-rw-r--r--lib/igt_rand.c19
1 files changed, 11 insertions, 8 deletions
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);
+}