Add random() and srandom()

Closes #123
This commit is contained in:
Justine Tunney 2021-03-13 20:24:29 -08:00
parent 807706a099
commit da4dffccc5
2 changed files with 132 additions and 1 deletions

View file

@ -6,7 +6,7 @@ COSMOPOLITAN_C_START_
cosmopolitan § random
*/
#define RAND_MAX __INT_MAX__ /* only applies to rand() */
#define RAND_MAX __INT_MAX__ /* only applies to rand() */
void srand(uint64_t) nothrow nocallback; /* seeds rand() only */
int rand(void) nothrow nocallback; /* ≥0 unseeded lcg prng */
uint32_t rand32(void) nothrow nocallback; /* random as possible rng */
@ -25,6 +25,9 @@ int64_t winrandish(void);
uint64_t rdrand(void);
uint64_t rdseed(void);
float randf(void);
char *initstate(unsigned, char *, size_t);
char *setstate(char *);
long random(void);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */