summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/rand.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdlib/rand.c')
-rw-r--r--lib/libc/stdlib/rand.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/libc/stdlib/rand.c b/lib/libc/stdlib/rand.c
index f270ffd9868..61fb66e5eca 100644
--- a/lib/libc/stdlib/rand.c
+++ b/lib/libc/stdlib/rand.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: rand.c,v 1.2 1996/08/19 08:33:44 tholo Exp $";
+static char *rcsid = "$OpenBSD: rand.c,v 1.3 1998/11/20 11:18:50 d Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -41,9 +41,17 @@ static char *rcsid = "$OpenBSD: rand.c,v 1.2 1996/08/19 08:33:44 tholo Exp $";
static u_long next = 1;
int
+rand_r(seed)
+u_int *seed;
+{
+ *seed = *seed * 1103515245 + 12345;
+ return (u_int)(*seed / 65536) % ((u_int)RAND_MAX + 1);
+}
+
+int
rand()
{
- return ((next = next * 1103515245 + 12345) % ((u_int)RAND_MAX + 1));
+ return rand_r(&next);
}
void