From: Sebastien Bourdeauducq Date: Fri, 25 May 2012 16:57:23 +0000 (+0200) Subject: software/libbase: srand and RAND_MAX X-Git-Tag: 24jan2021_ls180~3167 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8e0461121f15caae1433a6008eb6f00c7cfbf0e2;p=litex.git software/libbase: srand and RAND_MAX --- 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)