From 13d38be6e2ff2d5c1ed46dc22ddf3489a3206d02 Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Tue, 15 Nov 2011 23:33:05 +0330 Subject: [PATCH] stdlib.h: implement rand() and srand() --- rand.c | 14 ++++++++++++++ stdlib.h | 5 +++++ 2 files changed, 19 insertions(+) create mode 100644 rand.c diff --git a/rand.c b/rand.c new file mode 100644 index 0000000..13f5d20 --- /dev/null +++ b/rand.c @@ -0,0 +1,14 @@ +#include + +static unsigned r; + +void srand(unsigned int seed) +{ + r = seed; +} + +int rand(void) +{ + r = r * 1103515245 + 12345; + return r & 0x7fffffff; +} diff --git a/stdlib.h b/stdlib.h index fb80dc1..69630f4 100644 --- a/stdlib.h +++ b/stdlib.h @@ -1,5 +1,7 @@ #include +#define RAND_MAX 0x7fffffff + void *malloc(long n); void free(void *m); @@ -12,3 +14,6 @@ void abort(void); char *getenv(char *name); void qsort(void *a, int n, int sz, int (*cmp)(void *, void *)); int mkstemp(char *t); + +void srand(unsigned int seed); +int rand(void); -- 2.11.4.GIT