Module Name:    src
Committed By:   dholland
Date:           Mon May 25 00:37:27 UTC 2009

Modified Files:
        src/games/trek: main.c ranf.c setup.c

Log Message:
Use random() instead of rand(), so we get something like random
numbers out.

This changes the "tournament codes"; that is, the same code will give
you a different game now from what it used to. (This is because the
codes are basically random seeds.) I really really doubt anyone cares
about this, especially since the tournament feature appears to be
undocumented.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/games/trek/main.c
cvs rdiff -u -r1.6 -r1.7 src/games/trek/ranf.c
cvs rdiff -u -r1.12 -r1.13 src/games/trek/setup.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/trek/main.c
diff -u src/games/trek/main.c:1.21 src/games/trek/main.c:1.22
--- src/games/trek/main.c:1.21	Mon May 25 00:29:08 2009
+++ src/games/trek/main.c	Mon May 25 00:37:27 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.21 2009/05/25 00:29:08 dholland Exp $	*/
+/*	$NetBSD: main.c,v 1.22 2009/05/25 00:37:27 dholland Exp $	*/
 
 /*
  * Copyright (c) 1980, 1993
@@ -39,13 +39,12 @@
 #if 0
 static char sccsid[] = "@(#)main.c	8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: main.c,v 1.21 2009/05/25 00:29:08 dholland Exp $");
+__RCSID("$NetBSD: main.c,v 1.22 2009/05/25 00:37:27 dholland Exp $");
 #endif
 #endif /* not lint */
 
 #include <stdio.h>
 #include <setjmp.h>
-#include <termios.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <err.h>
@@ -165,8 +164,6 @@
 int
 main(int argc, char **argv)
 {
-	time_t		curtime;
-	long			vect;
 	int ch;
 
 	/* Revoke setgid privileges */
@@ -175,9 +172,7 @@
 	/* Default to fast mode */
 	Etc.fast = 1;
 
-	time(&curtime);
-	vect = (long) curtime;
-	srand(vect);
+	srandom((long) time(NULL));
 
 	while ((ch = getopt(argc, argv, "fst")) != -1) {
 		switch (ch) {

Index: src/games/trek/ranf.c
diff -u src/games/trek/ranf.c:1.6 src/games/trek/ranf.c:1.7
--- src/games/trek/ranf.c:1.6	Sun May 24 19:18:44 2009
+++ src/games/trek/ranf.c	Mon May 25 00:37:27 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: ranf.c,v 1.6 2009/05/24 19:18:44 dholland Exp $	*/
+/*	$NetBSD: ranf.c,v 1.7 2009/05/25 00:37:27 dholland Exp $	*/
 
 /*
  * Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)ranf.c	8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: ranf.c,v 1.6 2009/05/24 19:18:44 dholland Exp $");
+__RCSID("$NetBSD: ranf.c,v 1.7 2009/05/25 00:37:27 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -45,19 +45,14 @@
 int
 ranf(int max)
 {
-	int	t;
-
 	if (max <= 0)
 		return (0);
-	t = rand() >> 5;
-	return (t % max);
+	return (random() % max);
 }
 
 
 double
 franf(void)
 {
-	double		t;
-	t = rand() & 077777;
-	return (t / 32767.0);
+	return random() / (double)RANDOM_MAX;
 }

Index: src/games/trek/setup.c
diff -u src/games/trek/setup.c:1.12 src/games/trek/setup.c:1.13
--- src/games/trek/setup.c:1.12	Sun May 24 21:44:56 2009
+++ src/games/trek/setup.c	Mon May 25 00:37:27 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: setup.c,v 1.12 2009/05/24 21:44:56 dholland Exp $	*/
+/*	$NetBSD: setup.c,v 1.13 2009/05/25 00:37:27 dholland Exp $	*/
 
 /*
  * Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)setup.c	8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: setup.c,v 1.12 2009/05/24 21:44:56 dholland Exp $");
+__RCSID("$NetBSD: setup.c,v 1.13 2009/05/25 00:37:27 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -109,7 +109,7 @@
 		d = 0;
 		for (i = 0; Game.passwd[i]; i++)
 			d += Game.passwd[i] << i;
-		srand(d);
+		srandom(d);
 	}
 	Param.bases = Now.bases = ranf(6 - Game.skill) + 2;
 	if (Game.skill == 6)

Reply via email to