diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2010-06-11 14:10:36 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2010-06-22 15:44:44 +0200 |
commit | 738d70e430b0f4cb9ac71d2811b3f6a4c74abbf6 (patch) | |
tree | 195b9f1d664b93f77b0daaedb15260222c15d38f /lib | |
parent | 600c0e987e3a03c383dfb0c3ffe57c12d366cb1b (diff) | |
download | barebox-738d70e430b0f4cb9ac71d2811b3f6a4c74abbf6.tar.gz barebox-738d70e430b0f4cb9ac71d2811b3f6a4c74abbf6.tar.xz |
include support for a simple pseudo number generator
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile | 1 | ||||
-rw-r--r-- | lib/random.c | 26 |
2 files changed, 27 insertions, 0 deletions
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; +} + |