diff options
Diffstat (limited to 'sys/lib/libkern')
-rw-r--r-- | sys/lib/libkern/Makefile | 4 | ||||
-rw-r--r-- | sys/lib/libkern/libkern.h | 3 | ||||
-rw-r--r-- | sys/lib/libkern/random.c | 7 | ||||
-rw-r--r-- | sys/lib/libkern/srandom.c | 47 |
4 files changed, 55 insertions, 6 deletions
diff --git a/sys/lib/libkern/Makefile b/sys/lib/libkern/Makefile index 03c107b20ab..caee95f22a8 100644 --- a/sys/lib/libkern/Makefile +++ b/sys/lib/libkern/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.8 1996/06/16 01:14:20 deraadt Exp $ +# $OpenBSD: Makefile,v 1.9 1996/08/10 21:41:14 deraadt Exp $ # $NetBSD: Makefile,v 1.27 1996/05/10 21:27:32 scottr Exp $ LIB= kern @@ -24,7 +24,7 @@ SRCS+= adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c iordi3.c \ .endif # Other stuff -SRCS+= md5.c getsn.c +SRCS+= md5.c getsn.c srandom.c CLEANFILES+= lib${LIB}.o lib${LIB}.po diff --git a/sys/lib/libkern/libkern.h b/sys/lib/libkern/libkern.h index 7eae8a7b4bb..f43b98e6241 100644 --- a/sys/lib/libkern/libkern.h +++ b/sys/lib/libkern/libkern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: libkern.h,v 1.4 1996/06/16 01:14:21 deraadt Exp $ */ +/* $OpenBSD: libkern.h,v 1.5 1996/08/10 21:41:15 deraadt Exp $ */ /* $NetBSD: libkern.h,v 1.7 1996/03/14 18:52:08 christos Exp $ */ /*- @@ -117,6 +117,7 @@ int bcmp __P((const void *, const void *, size_t)); int ffs __P((int)); int locc __P((int, char *, u_int)); u_long random __P((void)); +void srandom __P((u_long)); char *rindex __P((const char *, int)); int scanc __P((u_int, u_char *, u_char *, int)); int skpc __P((int, size_t, u_char *)); diff --git a/sys/lib/libkern/random.c b/sys/lib/libkern/random.c index 14a10320f63..970cbf4bc6c 100644 --- a/sys/lib/libkern/random.c +++ b/sys/lib/libkern/random.c @@ -42,10 +42,11 @@ * and whatever else we might use it for. The result is uniform on * [0, 2^31 - 1]. */ +u_long __randseed = 1; + u_long random() { - static u_long randseed = 1; register long x, hi, lo, t; /* @@ -54,12 +55,12 @@ random() * Park and Miller, Communications of the ACM, vol. 31, no. 10, * October 1988, p. 1195. */ - x = randseed; + x = __randseed; hi = x / 127773; lo = x % 127773; t = 16807 * lo - 2836 * hi; if (t <= 0) t += 0x7fffffff; - randseed = t; + __randseed = t; return (t); } diff --git a/sys/lib/libkern/srandom.c b/sys/lib/libkern/srandom.c new file mode 100644 index 00000000000..3a88b00fe1d --- /dev/null +++ b/sys/lib/libkern/srandom.c @@ -0,0 +1,47 @@ +/* $OpenBSD: srandom.c,v 1.1 1996/08/10 21:41:16 deraadt Exp $ */ + +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)random.c 8.1 (Berkeley) 6/10/93 + */ + +#include <sys/types.h> + +extern u_long _randseed; + +void +srandom(seed) + u_long seed; +{ + _randseed = seed; +} |