Module Name: src
Committed By: rillig
Date: Sat May 1 21:10:57 UTC 2021
Modified Files:
src/games/fish: fish.c
Log Message:
fish: remove modulo bias from random number generation
It probably doesn't matter in practice, but omitting this piece of code
always looks like an oversight.
To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/games/fish/fish.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/fish/fish.c
diff -u src/games/fish/fish.c:1.23 src/games/fish/fish.c:1.24
--- src/games/fish/fish.c:1.23 Mon Mar 5 04:59:54 2018
+++ src/games/fish/fish.c Sat May 1 21:10:57 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: fish.c,v 1.23 2018/03/05 04:59:54 eadler Exp $ */
+/* $NetBSD: fish.c,v 1.24 2021/05/01 21:10:57 rillig Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 19
#if 0
static char sccsid[] = "@(#)fish.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: fish.c,v 1.23 2018/03/05 04:59:54 eadler Exp $");
+__RCSID("$NetBSD: fish.c,v 1.24 2021/05/01 21:10:57 rillig Exp $");
#endif
#endif /* not lint */
@@ -435,8 +435,13 @@ init(void)
static int
nrandom(int n)
{
+ long r;
- return((int)random() % n);
+ for (;;) {
+ r = random();
+ if (r < RANDOM_MAX - RANDOM_MAX % n)
+ return (int)(r % n);
+ }
}
static void