summaryrefslogtreecommitdiff
path: root/userland/libc/stdlib/rand.c
diff options
context:
space:
mode:
Diffstat (limited to 'userland/libc/stdlib/rand.c')
-rw-r--r--userland/libc/stdlib/rand.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/userland/libc/stdlib/rand.c b/userland/libc/stdlib/rand.c
new file mode 100644
index 0000000..e186af7
--- /dev/null
+++ b/userland/libc/stdlib/rand.c
@@ -0,0 +1,17 @@
+#include <stdint.h>
+#include <stdlib.h>
+
+uint32_t xorshift(uint32_t x) {
+ uint32_t f = x;
+ x ^= x << 13;
+ x ^= x >> 17;
+ x ^= x << 5;
+ return f + x;
+}
+
+extern uint32_t __INTERNAL_RNG_STATE;
+int rand(void) {
+ uint32_t x = xorshift(__INTERNAL_RNG_STATE);
+ __INTERNAL_RNG_STATE++;
+ return x;
+}