Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games/fortune/fortune backout previous (arc4random), per req...



details:   https://anonhg.NetBSD.org/src/rev/e6a1f463b10a
branches:  trunk
changeset: 533488:e6a1f463b10a
user:      itojun <itojun%NetBSD.org@localhost>
date:      Mon Jul 01 20:55:30 2002 +0000

description:
backout previous (arc4random), per request from sommerfeld

diffstat:

 games/fortune/fortune/fortune.c |  23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)

diffs (91 lines):

diff -r 6bb3fa086106 -r e6a1f463b10a games/fortune/fortune/fortune.c
--- a/games/fortune/fortune/fortune.c   Mon Jul 01 20:51:25 2002 +0000
+++ b/games/fortune/fortune/fortune.c   Mon Jul 01 20:55:30 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fortune.c,v 1.35 2002/07/01 14:51:52 itojun Exp $      */
+/*     $NetBSD: fortune.c,v 1.36 2002/07/01 20:55:30 itojun Exp $      */
 
 /*-
  * Copyright (c) 1986, 1993
@@ -46,7 +46,7 @@
 #if 0
 static char sccsid[] = "@(#)fortune.c  8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: fortune.c,v 1.35 2002/07/01 14:51:52 itojun Exp $");
+__RCSID("$NetBSD: fortune.c,v 1.36 2002/07/01 20:55:30 itojun Exp $");
 #endif
 #endif /* not lint */
 
@@ -220,6 +220,7 @@
        int     ac;
        char    *av[];
 {
+       struct timeval tv;
 #ifdef OK_TO_WRITE_DISK
        int     fd;
 #endif /* OK_TO_WRITE_DISK */
@@ -232,6 +233,12 @@
 #endif
 
        init_prob();
+       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) ||
@@ -974,7 +981,7 @@
        if (File_list->next == NULL || File_list->percent == NO_PROB)
                fp = File_list;
        else {
-               choice = arc4random() % 100;
+               choice = random() % 100;
                DPRINTF(1, (stderr, "choice = %d\n", choice));
                for (fp = File_list; fp->percent != NO_PROB; fp = fp->next)
                        if (choice < fp->percent)
@@ -994,7 +1001,7 @@
        else {
                if (fp->next != NULL) {
                        sum_noprobs(fp);
-                       choice = arc4random() % Noprob_tbl.str_numstr;
+                       choice = random() % Noprob_tbl.str_numstr;
                        DPRINTF(1, (stderr, "choice = %d (of %d) \n", choice,
                                    Noprob_tbl.str_numstr));
                        while ((u_int32_t)choice >= fp->tbl.str_numstr) {
@@ -1036,7 +1043,7 @@
        int              choice;
 
        if (Equal_probs) {
-               choice = arc4random() % parent->num_children;
+               choice = random() % parent->num_children;
                DPRINTF(1, (stderr, "    choice = %d (of %d)\n",
                            choice, parent->num_children));
                for (fp = parent->child; choice--; fp = fp->next)
@@ -1046,7 +1053,7 @@
        }
        else {
                get_tbl(parent);
-               choice = arc4random() % parent->tbl.str_numstr;
+               choice = random() % parent->tbl.str_numstr;
                DPRINTF(1, (stderr, "    choice = %d (of %d)\n",
                            choice, parent->tbl.str_numstr));
                for (fp = parent->child; (u_int32_t)choice >= fp->tbl.str_numstr;
@@ -1131,13 +1138,13 @@
 #ifdef OK_TO_WRITE_DISK
                if ((fd = open(fp->posfile, O_RDONLY)) < 0 ||
                    read(fd, &fp->pos, sizeof fp->pos) != sizeof fp->pos)
-                       fp->pos = arc4random() % fp->tbl.str_numstr;
+                       fp->pos = random() % fp->tbl.str_numstr;
                else if (fp->pos >= fp->tbl.str_numstr)
                        fp->pos %= fp->tbl.str_numstr;
                if (fd >= 0)
                        (void) close(fd);
 #else
-               fp->pos = arc4random() % fp->tbl.str_numstr;
+               fp->pos = random() % fp->tbl.str_numstr;
 #endif /* OK_TO_WRITE_DISK */
        }
        if ((u_int64_t)++(fp->pos) >= fp->tbl.str_numstr)



Home | Main Index | Thread Index | Old Index