aboutsummaryrefslogtreecommitdiff
path: root/lib/rand.c
diff options
context:
space:
mode:
authorthead_admin <occ_thead@service.alibaba.com>2022-09-13 11:04:33 +0800
committerthead_admin <occ_thead@service.alibaba.com>2022-09-13 11:04:33 +0800
commit43db9e00d5837c100c0b2fbbee64a08ab807d1e0 (patch)
treeb40c0eed02935b6682e8c5c975e3016b6b2f55fe /lib/rand.c
Linux_SDK_V0.9.5Linux_SDK_V0.9.5
Diffstat (limited to 'lib/rand.c')
-rw-r--r--lib/rand.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/rand.c b/lib/rand.c
new file mode 100644
index 00000000..d256baf5
--- /dev/null
+++ b/lib/rand.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Simple xorshift PRNG
+ * see http://www.jstatsoft.org/v08/i14/paper
+ *
+ * Copyright (c) 2012 Michael Walle
+ * Michael Walle <michael@walle.cc>
+ */
+
+#include <common.h>
+#include <rand.h>
+
+static unsigned int y = 1U;
+
+unsigned int rand_r(unsigned int *seedp)
+{
+ *seedp ^= (*seedp << 13);
+ *seedp ^= (*seedp >> 17);
+ *seedp ^= (*seedp << 5);
+
+ return *seedp;
+}
+
+unsigned int rand(void)
+{
+ return rand_r(&y);
+}
+
+void srand(unsigned int seed)
+{
+ y = seed;
+}