summaryrefslogtreecommitdiffstats
path: root/lib/random.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/random.c')
-rw-r--r--lib/random.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/random.c b/lib/random.c
new file mode 100644
index 0000000000..352d6bf3f7
--- /dev/null
+++ b/lib/random.c
@@ -0,0 +1,26 @@
+#include <common.h>
+#include <stdlib.h>
+
+static unsigned int random_seed;
+
+#if RAND_MAX > 32767
+#error this rand implementation is for RAND_MAX < 32678 only.
+#endif
+
+unsigned int rand(void)
+{
+ random_seed = random_seed * 1103515245 + 12345;
+ return (random_seed / 65536) % (RAND_MAX + 1);
+}
+
+void srand(unsigned int seed)
+{
+ random_seed = seed;
+}
+
+void get_random_bytes(char *buf, int len)
+{
+ while (len--)
+ *buf++ = rand() % 256;
+}
+