summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/net.h1
-rw-r--r--include/stdlib.h16
-rw-r--r--lib/Makefile1
-rw-r--r--lib/random.c26
4 files changed, 44 insertions, 0 deletions
diff --git a/include/net.h b/include/net.h
index 8db83d8309..709e76c895 100644
--- a/include/net.h
+++ b/include/net.h
@@ -16,6 +16,7 @@
#include <linux/types.h>
#include <param.h>
#include <malloc.h>
+#include <stdlib.h>
#include <asm/byteorder.h> /* for nton* / ntoh* stuff */
diff --git a/include/stdlib.h b/include/stdlib.h
new file mode 100644
index 0000000000..dc720132e8
--- /dev/null
+++ b/include/stdlib.h
@@ -0,0 +1,16 @@
+#ifndef __STDLIB_H
+#define __STDLIB_H
+
+#define RAND_MAX 32767
+
+/* return a pseudo-random integer in the range [0, RAND_MAX] */
+unsigned int rand(void);
+
+/* set the seed for rand () */
+void srand(unsigned int seed);
+
+/* fill a buffer with pseudo-random data */
+void get_random_bytes(char *buf, int len);
+
+
+#endif /* __STDLIB_H */
diff --git a/lib/Makefile b/lib/Makefile
index b072fb6bea..4a33aaa3c0 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o
obj-y += glob.o
obj-y += notifier.o
obj-y += copy_file.o
+obj-y += random.o
obj-y += lzo/
obj-$(CONFIG_LZO_DECOMPRESS) += decompress_unlzo.o
obj-$(CONFIG_PROCESS_ESCAPE_SEQUENCE) += process_escape_sequence.o
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;
+}
+