summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/rand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/stdlib/rand.c')
-rw-r--r--src/lib/libc/stdlib/rand.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/lib/libc/stdlib/rand.c b/src/lib/libc/stdlib/rand.c
index 361d473448..bb180886c0 100644
--- a/src/lib/libc/stdlib/rand.c
+++ b/src/lib/libc/stdlib/rand.c
@@ -32,24 +32,34 @@
32 */ 32 */
33 33
34#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
35/*static char *sccsid = "from: @(#)rand.c 5.6 (Berkeley) 6/24/91";*/ 35static char *rcsid = "$OpenBSD: rand.c,v 1.6 1998/12/07 21:47:22 millert Exp $";
36static char *rcsid = "$Id: rand.c,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $";
37#endif /* LIBC_SCCS and not lint */ 36#endif /* LIBC_SCCS and not lint */
38 37
39#include <sys/types.h> 38#include <sys/types.h>
40#include <stdlib.h> 39#include <stdlib.h>
41 40
42static u_long next = 1; 41static u_int next = 1;
42
43int
44rand_r(seed)
45u_int *seed;
46{
47
48 *seed = *seed * 1103515245 + 12345;
49 return (*seed % ((u_int)RAND_MAX + 1));
50}
43 51
44int 52int
45rand() 53rand()
46{ 54{
47 return ((next = next * 1103515245 + 12345) % ((u_int)RAND_MAX + 1)); 55
56 return (rand_r(&next));
48} 57}
49 58
50void 59void
51srand(seed) 60srand(seed)
52u_int seed; 61u_int seed;
53{ 62{
63
54 next = seed; 64 next = seed;
55} 65}