summaryrefslogtreecommitdiffstats
path: root/fortune
diff options
context:
space:
mode:
authorproff <proff@NetBSD.org>2001-10-28 19:47:48 +0000
committerproff <proff@NetBSD.org>2001-10-28 19:47:48 +0000
commit55897f8f7c105946fb5763a36e20db423fdced1e (patch)
tree9f2ee031a82dd8b99de1ed508ca9cfd5e6f1911b /fortune
parentecafa192e2fdcc4c638a86e510129feb6873307e (diff)
downloadbsdgames-darwin-55897f8f7c105946fb5763a36e20db423fdced1e.tar.gz
bsdgames-darwin-55897f8f7c105946fb5763a36e20db423fdced1e.tar.zst
bsdgames-darwin-55897f8f7c105946fb5763a36e20db423fdced1e.zip
improve random number seeding
Diffstat (limited to 'fortune')
-rw-r--r--fortune/fortune/fortune.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/fortune/fortune/fortune.c b/fortune/fortune/fortune.c
index 73cf0078..0f8034fb 100644
--- a/fortune/fortune/fortune.c
+++ b/fortune/fortune/fortune.c
@@ -1,4 +1,4 @@
-/* $NetBSD: fortune.c,v 1.30 2001/08/15 17:25:42 atatat Exp $ */
+/* $NetBSD: fortune.c,v 1.31 2001/10/28 19:47:48 proff Exp $ */
/*-
* Copyright (c) 1986, 1993
@@ -46,12 +46,13 @@ __COPYRIGHT("@(#) Copyright (c) 1986, 1993\n\
#if 0
static char sccsid[] = "@(#)fortune.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: fortune.c,v 1.30 2001/08/15 17:25:42 atatat Exp $");
+__RCSID("$NetBSD: fortune.c,v 1.31 2001/10/28 19:47:48 proff Exp $");
#endif
#endif /* not lint */
# include <sys/param.h>
# include <sys/stat.h>
+# include <sys/time.h>
# include <dirent.h>
# include <fcntl.h>
@@ -219,6 +220,7 @@ main(ac, av)
int ac;
char *av[];
{
+ struct timeval tv;
#ifdef OK_TO_WRITE_DISK
int fd;
#endif /* OK_TO_WRITE_DISK */
@@ -231,10 +233,15 @@ main(ac, av)
#endif
init_prob();
- srandom((int)(time((time_t *) NULL) ^ getpid() * getpid()));
+ if (gettimeofday(&tv, NULL) != 0)
+ err(1, "gettimeofday()");
+ srandom(((unsigned long)tv.tv_sec) *
+ ((unsigned long)tv.tv_usec+1) *
+ ((unsigned long)getpid()+1) *
+ ((unsigned long)getppid()+1));
do {
- get_fort();
- } while ((Short_only && fortlen() > SLEN) ||
+ get_fort(); } while ((Short_only && fortlen() >
+ SLEN) ||
(Long_only && fortlen() <= SLEN));
display(Fortfile);