Source-Changes-HG archive

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

[src/trunk]: src/games/tetris tetris: Use arc4random_uniform instead of modul...



details:   https://anonhg.NetBSD.org/src/rev/abdaadb2db47
branches:  trunk
changeset: 936204:abdaadb2db47
user:      nia <nia%NetBSD.org@localhost>
date:      Tue Jul 21 02:42:05 2020 +0000

description:
tetris: Use arc4random_uniform instead of modulo for better randomness

diffstat:

 games/tetris/tetris.c |  3 +--
 games/tetris/tetris.h |  4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)

diffs (35 lines):

diff -r 9d5895234086 -r abdaadb2db47 games/tetris/tetris.c
--- a/games/tetris/tetris.c     Tue Jul 21 02:21:12 2020 +0000
+++ b/games/tetris/tetris.c     Tue Jul 21 02:42:05 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tetris.c,v 1.32 2016/03/03 21:38:55 nat Exp $  */
+/*     $NetBSD: tetris.c,v 1.33 2020/07/21 02:42:05 nia Exp $  */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -207,7 +207,6 @@
        scr_init();
        setup_board();
 
-       srandom(getpid());
        scr_set();
 
        pos = A_FIRST*B_COLS + (B_COLS/2)-1;
diff -r 9d5895234086 -r abdaadb2db47 games/tetris/tetris.h
--- a/games/tetris/tetris.h     Tue Jul 21 02:21:12 2020 +0000
+++ b/games/tetris/tetris.h     Tue Jul 21 02:42:05 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tetris.h,v 1.15 2016/03/03 21:38:55 nat Exp $  */
+/*     $NetBSD: tetris.h,v 1.16 2020/07/21 02:42:05 nia Exp $  */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -130,7 +130,7 @@
 };
 
 extern const struct shape shapes[];
-#define        randshape() (&shapes[random() % 7])
+#define        randshape() (&shapes[arc4random_uniform(7)])
 
 extern const struct shape *nextshape;
 



Home | Main Index | Thread Index | Old Index