mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
software/libbase: srand and RAND_MAX
This commit is contained in:
parent
88a909e86c
commit
8e0461121f
2 changed files with 11 additions and 3 deletions
|
@ -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 */
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue