Loading...
--- Libc/Libc-1725.40.4/stdlib/FreeBSD/rand.c
+++ Libc/Libc-320/stdlib/FreeBSD/rand.c
@@ -10,6 +10,10 @@
* 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.
@@ -33,7 +37,7 @@
static char sccsid[] = "@(#)rand.c 8.1 (Berkeley) 6/14/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: src/lib/libc/stdlib/rand.c,v 1.15 2003/02/17 03:52:35 ache Exp $");
#include "namespace.h"
#include <sys/time.h> /* for sranddev() */
@@ -60,7 +64,7 @@
#else /* !USE_WEAK_SEEDING */
/*
* Compute x = (7^5 * x) mod (2^31 - 1)
- * without overflowing 31 bits:
+ * wihout overflowing 31 bits:
* (2^31 - 1) = 127773 * (7^5) + 2836
* From "Random number generators: good ones are hard to find",
* Park and Miller, Communications of the ACM, vol. 31, no. 10,
@@ -95,13 +99,14 @@
static u_long next = 1;
int
-rand(void)
+rand()
{
return (do_rand(&next));
}
void
-srand(u_int seed)
+srand(seed)
+u_int seed;
{
next = seed;
}
@@ -115,12 +120,12 @@
* secure random(4) interface.
*/
void
-sranddev(void)
+sranddev()
{
int fd, done;
done = 0;
- fd = _open("/dev/random", O_RDONLY | O_CLOEXEC, 0);
+ fd = _open("/dev/random", O_RDONLY, 0);
if (fd >= 0) {
if (_read(fd, (void *) &next, sizeof(next)) == sizeof(next))
done = 1;
@@ -129,9 +134,10 @@
if (!done) {
struct timeval tv;
+ unsigned long junk;
gettimeofday(&tv, NULL);
- srand((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec);
+ srand((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk);
}
}