From 8e0461121f15caae1433a6008eb6f00c7cfbf0e2 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 25 May 2012 18:57:23 +0200 Subject: [PATCH] software/libbase: srand and RAND_MAX --- software/include/base/stdlib.h | 3 +++ software/libbase/libc.c | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/software/include/base/stdlib.h b/software/include/base/stdlib.h index 685cc5a6..cea677d5 100644 --- a/software/include/base/stdlib.h +++ b/software/include/base/stdlib.h @@ -49,7 +49,10 @@ char *number(char *buf, char *end, unsigned long num, int base, int size, int pr long strtol(const char *nptr, char **endptr, int base); float atof(const char *s); +#define RAND_MAX 2147483647 + unsigned int rand(void); +void srand(unsigned int seed); void abort(void); #endif /* __STDLIB_H */ diff --git a/software/libbase/libc.c b/software/libbase/libc.c index 565927a5..18b7f90a 100644 --- a/software/libbase/libc.c +++ b/software/libbase/libc.c @@ -563,11 +563,16 @@ int sprintf(char * buf, const char *fmt, ...) * rand - Returns a pseudo random number */ -static unsigned int seed; +static unsigned int randseed; unsigned int rand(void) { - seed = 129 * seed + 907633385; - return seed; + randseed = 129 * randseed + 907633385; + return randseed; +} + +void srand(unsigned int seed) +{ + randseed = seed; } void abort(void) -- 2.30.2