summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornia <nia@NetBSD.org>2020-07-26 15:38:22 +0000
committernia <nia@NetBSD.org>2020-07-26 15:38:22 +0000
commitf0829a8fa8ff202a2ad46e191e3ab4650780bbe6 (patch)
tree8e5e66ff0b10aad245d9307d58f07f39a3d90336
parentb44443a36db16ebbfcdf801559c33b00e0f3f60e (diff)
downloadbsdgames-darwin-f0829a8fa8ff202a2ad46e191e3ab4650780bbe6.tar.gz
bsdgames-darwin-f0829a8fa8ff202a2ad46e191e3ab4650780bbe6.tar.zst
bsdgames-darwin-f0829a8fa8ff202a2ad46e191e3ab4650780bbe6.zip
robots: Use arc4random_uniform for better uniform distribution
-rw-r--r--robots/main.c5
-rw-r--r--robots/rnd_pos.c17
2 files changed, 6 insertions, 16 deletions
diff --git a/robots/main.c b/robots/main.c
index 7a38b3d0..3030b412 100644
--- a/robots/main.c
+++ b/robots/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.32 2009/08/12 08:30:55 dholland Exp $ */
+/* $NetBSD: main.c,v 1.33 2020/07/26 15:38:22 nia Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: main.c,v 1.32 2009/08/12 08:30:55 dholland Exp $");
+__RCSID("$NetBSD: main.c,v 1.33 2020/07/26 15:38:22 nia Exp $");
#endif
#endif /* not lint */
@@ -167,7 +167,6 @@ main(int argc, char **argv)
stdscr = newwin(Y_SIZE, X_SIZE, 0, 0);
}
- srandom(time(NULL));
if (Real_time)
signal(SIGALRM, move_robots);
do {
diff --git a/robots/rnd_pos.c b/robots/rnd_pos.c
index 5fe2cc04..8b1c416f 100644
--- a/robots/rnd_pos.c
+++ b/robots/rnd_pos.c
@@ -1,4 +1,4 @@
-/* $NetBSD: rnd_pos.c,v 1.10 2009/08/12 08:30:55 dholland Exp $ */
+/* $NetBSD: rnd_pos.c,v 1.11 2020/07/26 15:38:22 nia Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)rnd_pos.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: rnd_pos.c,v 1.10 2009/08/12 08:30:55 dholland Exp $");
+__RCSID("$NetBSD: rnd_pos.c,v 1.11 2020/07/26 15:38:22 nia Exp $");
#endif
#endif /* not lint */
@@ -44,8 +44,6 @@ __RCSID("$NetBSD: rnd_pos.c,v 1.10 2009/08/12 08:30:55 dholland Exp $");
#define IS_SAME(p,y,x) ((p).y != -1 && (p).y == y && (p).x == x)
-static int rnd(int);
-
/*
* rnd_pos:
* Pick a random, unoccupied position
@@ -57,17 +55,10 @@ rnd_pos(void)
static int call = 0;
do {
- pos.y = rnd(Y_FIELDSIZE - 1) + 1;
- pos.x = rnd(X_FIELDSIZE - 1) + 1;
+ pos.y = arc4random_uniform(Y_FIELDSIZE - 1) + 1;
+ pos.x = arc4random_uniform(X_FIELDSIZE - 1) + 1;
refresh();
} while (Field[pos.y][pos.x] != 0);
call++;
return &pos;
}
-
-static int
-rnd(int range)
-{
-
- return random() % range;
-}