summaryrefslogtreecommitdiff
path: root/lib/igt_rand.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/igt_rand.c')
-rw-r--r--lib/igt_rand.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/igt_rand.c b/lib/igt_rand.c
new file mode 100644
index 00000000..a3298a9f
--- /dev/null
+++ b/lib/igt_rand.c
@@ -0,0 +1,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
+}