diff --git a/software/include/base/stdlib.h b/software/include/base/stdlib.h index 685cc5a61..cea677d50 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 565927a5a..18b7f90a8 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)