This replaces srandomdev()+random() with calls to arc4random*() in src/games. There isn't much practical benefit to this. Consider it a style fix.
I have NOT touched the games that call srandom() with a particular seed for deterministic gameplay. Index: arithmetic/arithmetic.c =================================================================== RCS file: /cvs/src/games/arithmetic/arithmetic.c,v retrieving revision 1.17 diff -u -p -r1.17 arithmetic.c --- arithmetic/arithmetic.c 27 Oct 2009 23:59:23 -0000 1.17 +++ arithmetic/arithmetic.c 28 Aug 2013 14:30:16 -0000 @@ -124,9 +124,6 @@ main(int argc, char *argv[]) if (argc -= optind) usage(); - /* Seed the random-number generator. */ - srandomdev(); - (void)signal(SIGINT, intr); /* Now ask the questions. */ @@ -177,7 +174,7 @@ problem(void) int left, op, right, result; char line[80]; - op = keys[random() % nkeys]; + op = keys[arc4random_uniform(nkeys)]; if (op != '/') right = getrandom(rangemax + 1, op, 1); retry: @@ -198,7 +195,7 @@ retry: case '/': right = getrandom(rangemax, op, 1) + 1; result = getrandom(rangemax + 1, op, 0); - left = right * result + random() % right; + left = right * result + arc4random_uniform(right); break; } @@ -308,7 +305,7 @@ getrandom(int maxval, int op, int operan struct penalty **pp, *p; op = opnum(op); - value = random() % (maxval + penalty[op][operand]); + value = arc4random_uniform(maxval + penalty[op][operand]); /* * 0 to maxval - 1 is a number to be used directly; bigger values Index: backgammon/backgammon/main.c =================================================================== RCS file: /cvs/src/games/backgammon/backgammon/main.c,v retrieving revision 1.16 diff -u -p -r1.16 main.c --- backgammon/backgammon/main.c 27 Oct 2009 23:59:23 -0000 1.16 +++ backgammon/backgammon/main.c 28 Aug 2013 14:34:54 -0000 @@ -100,7 +100,6 @@ main (argc,argv) /* use whole screen for text */ begscr = 0; - srandomdev(); /* seed random number generator */ getarg(argc, argv); args[acnt] = '\0'; Index: backgammon/common_source/back.h =================================================================== RCS file: /cvs/src/games/backgammon/common_source/back.h,v retrieving revision 1.11 diff -u -p -r1.11 back.h --- backgammon/common_source/back.h 14 Dec 2006 10:14:05 -0000 1.11 +++ backgammon/common_source/back.h 28 Aug 2013 14:35:11 -0000 @@ -43,7 +43,7 @@ #include <term.h> #include <unistd.h> -#define rnum(r) (random()%r) +#define rnum(r) arc4random_uniform(r) #define D0 dice[0] #define D1 dice[1] #define swap {D0 ^= D1; D1 ^= D0; D0 ^= D1; d0 = 1-d0;} Index: battlestar/extern.h =================================================================== RCS file: /cvs/src/games/battlestar/extern.h,v retrieving revision 1.14 diff -u -p -r1.14 extern.h --- battlestar/extern.h 5 Apr 2013 01:28:27 -0000 1.14 +++ battlestar/extern.h 28 Aug 2013 14:36:46 -0000 @@ -49,7 +49,7 @@ #define BITS (8 * sizeof (int)) #define OUTSIDE (position > 68 && position < 246 && position != 218) -#define rnd(x) (random() % (x)) +#define rnd(x) arc4random_uniform(x) #define max(a,b) ((a) < (b) ? (b) : (a)) /* avoid name collision with sys/param.h */ #define TestBit(array, index) (array[index/BITS] & (1 << (index % BITS))) Index: battlestar/init.c =================================================================== RCS file: /cvs/src/games/battlestar/init.c,v retrieving revision 1.13 diff -u -p -r1.13 init.c --- battlestar/init.c 27 Oct 2009 23:59:24 -0000 1.13 +++ battlestar/init.c 28 Aug 2013 14:37:03 -0000 @@ -46,7 +46,6 @@ initialize(const char *filename) puts("First Adventure game written by His Lordship, the honorable"); puts("Admiral D.W. Riggle\n"); location = dayfile; - srandomdev(); username = getutmp(); if (username == NULL) errx(1, "Don't know who you are."); Index: bs/bs.c =================================================================== RCS file: /cvs/src/games/bs/bs.c,v retrieving revision 1.23 diff -u -p -r1.23 bs.c --- bs/bs.c 14 Nov 2009 02:20:43 -0000 1.23 +++ bs/bs.c 28 Aug 2013 14:39:39 -0000 @@ -39,8 +39,6 @@ * v2.2 with bugfixes and strategical improvements, March 1998. */ -/* #define _POSIX_SOURCE */ /* ( random() ) */ - #include <sys/param.h> #include <sys/types.h> #include <curses.h> @@ -235,8 +233,6 @@ static void intro(void) { char *tmpname; - srandomdev(); /* Kick the random number generator */ - (void) signal(SIGINT,uninitgame); (void) signal(SIGINT,uninitgame); if(signal(SIGQUIT,SIG_IGN) != SIG_IGN) @@ -344,7 +340,7 @@ static void placeship(int b, ship_t *ss, static int rnd(int n) { - return(((random() & 0x7FFF) % n)); + return(arc4random_uniform(n)); } static void randomplace(int b, ship_t *ss) Index: canfield/canfield/canfield.c =================================================================== RCS file: /cvs/src/games/canfield/canfield/canfield.c,v retrieving revision 1.12 diff -u -p -r1.12 canfield.c --- canfield/canfield/canfield.c 27 Oct 2009 23:59:24 -0000 1.12 +++ canfield/canfield/canfield.c 28 Aug 2013 14:41:09 -0000 @@ -534,7 +534,7 @@ shuffle(struct cardtype *deck[]) deck[i]->paid = FALSE; } for (i = decksize-1; i>=0; i--) { - j = random() % decksize; + j = arc4random_uniform(decksize); if (i != j) { temp = deck[i]; deck[i] = deck[j]; @@ -1630,7 +1630,6 @@ initall(void) { int i; - srandomdev(); time(&acctstart); initdeck(deck); uid = getuid(); Index: fish/fish.c =================================================================== RCS file: /cvs/src/games/fish/fish.c,v retrieving revision 1.15 diff -u -p -r1.15 fish.c --- fish/fish.c 27 Oct 2009 23:59:24 -0000 1.15 +++ fish/fish.c 28 Aug 2013 14:43:26 -0000 @@ -98,7 +98,6 @@ main(int argc, char *argv[]) usage(); } - srandomdev(); instructions(); init(); @@ -412,7 +411,7 @@ init(void) int nrandom(int n) { - return((int)random() % n); + return(arc4random_uniform(n)); } int Index: fortune/strfile/strfile.c =================================================================== RCS file: /cvs/src/games/fortune/strfile/strfile.c,v retrieving revision 1.18 diff -u -p -r1.18 strfile.c --- fortune/strfile/strfile.c 22 Aug 2013 04:43:41 -0000 1.18 +++ fortune/strfile/strfile.c 27 Aug 2013 22:24:30 -0000 @@ -427,8 +427,6 @@ randomize(void) int32_t tmp; int32_t *sp; - srandomdev(); - Tbl.str_flags |= STR_RANDOM; cnt = Tbl.str_numstr; @@ -437,7 +435,7 @@ randomize(void) */ for (sp = Seekpts; cnt > 0; cnt--, sp++) { - i = random() % cnt; + i = arc4random_uniform(cnt); tmp = sp[0]; sp[0] = sp[i]; sp[i] = tmp; Index: gomoku/main.c =================================================================== RCS file: /cvs/src/games/gomoku/main.c,v retrieving revision 1.23 diff -u -p -r1.23 main.c --- gomoku/main.c 4 Mar 2012 04:05:15 -0000 1.23 +++ gomoku/main.c 28 Aug 2013 14:44:21 -0000 @@ -128,8 +128,6 @@ main(argc, argv) if (!debug) #ifdef SVR4 srand(time(0)); -#else - srandomdev(); #endif if (interactive) cursinit(); /* initialize curses */ Index: gomoku/pickmove.c =================================================================== RCS file: /cvs/src/games/gomoku/pickmove.c,v retrieving revision 1.11 diff -u -p -r1.11 pickmove.c --- gomoku/pickmove.c 27 Oct 2009 23:59:24 -0000 1.11 +++ gomoku/pickmove.c 28 Aug 2013 14:45:00 -0000 @@ -206,7 +206,7 @@ better(sp, sp1, us) #ifdef SVR4 return (rand() & 1); #else - return ((int)random() & 1); + return (arc4random() & 1); #endif } Index: hangman/getword.c =================================================================== RCS file: /cvs/src/games/hangman/getword.c,v retrieving revision 1.7 diff -u -p -r1.7 getword.c --- hangman/getword.c 27 Oct 2009 23:59:25 -0000 1.7 +++ hangman/getword.c 28 Aug 2013 14:47:43 -0000 @@ -30,6 +30,7 @@ * SUCH DAMAGE. */ +#include <stdint.h> #include <stdlib.h> #include "hangman.h" #include "pathnames.h" @@ -54,7 +55,8 @@ getword(void) while (badwords < MAXBADWORDS) { if (countwords) badwords++; - pos = (double) random() / (RAND_MAX + 1.0) * (double) Dict_size; + pos = (double) arc4random() / (UINT32_MAX + 1.0) * + (double) Dict_size; fseek(inf, pos, SEEK_SET); if (fgets(Word, BUFSIZ, inf) == NULL) continue; Index: hangman/ksyms.c =================================================================== RCS file: /cvs/src/games/hangman/ksyms.c,v retrieving revision 1.1 diff -u -p -r1.1 ksyms.c --- hangman/ksyms.c 1 Apr 2008 21:05:50 -0000 1.1 +++ hangman/ksyms.c 28 Aug 2013 14:49:12 -0000 @@ -20,6 +20,7 @@ #include <ctype.h> #include <errno.h> #include <fcntl.h> +#include <stdint.h> #include <string.h> #include <sys/exec.h> @@ -42,7 +43,8 @@ kgetword() size_t symlen; for (tries = 0; tries < MAXBADWORDS; tries++) { - pos = (double) random() / (RAND_MAX + 1.0) * (double)ksymsize; + pos = (double) arc4random() / (UINT32_MAX + 1.0) * + (double)ksymsize; if (lseek(ksyms, pos + ksymoffs, SEEK_SET) == -1) continue; buflen = read(ksyms, symbuf, BUFSIZ); Index: hangman/setup.c =================================================================== RCS file: /cvs/src/games/hangman/setup.c,v retrieving revision 1.10 diff -u -p -r1.10 setup.c --- hangman/setup.c 27 Oct 2009 23:59:25 -0000 1.10 +++ hangman/setup.c 28 Aug 2013 14:46:10 -0000 @@ -58,7 +58,6 @@ setup(void) addstr(*sp); } - srandomdev(); if (ksyms) { if (ksetup() != 0) { endwin(); Index: hunt/hunt/otto.c =================================================================== RCS file: /cvs/src/games/hunt/hunt/otto.c,v retrieving revision 1.9 diff -u -p -r1.9 otto.c --- hunt/hunt/otto.c 27 Mar 2006 00:10:15 -0000 1.9 +++ hunt/hunt/otto.c 28 Aug 2013 14:52:39 -0000 @@ -544,15 +544,15 @@ wander() break; } if (j == FRONT - && num_turns > 4 + (random() % - ((flbr[FRONT].flags & BEEN) ? 7 : HEIGHT))) + && num_turns > 4 + (arc4random_uniform( + ((flbr[FRONT].flags & BEEN) ? 7 : HEIGHT)))) continue; dir_mask |= 1 << j; dir_count = 1; break; } if (dir_count == 0) { - duck(random() % NUMDIRECTIONS); + duck(arc4random_uniform(NUMDIRECTIONS)); num_turns = 0; return; } else { Index: hunt/huntd/driver.c =================================================================== RCS file: /cvs/src/games/hunt/huntd/driver.c,v retrieving revision 1.19 diff -u -p -r1.19 driver.c --- hunt/huntd/driver.c 10 Dec 2009 23:53:06 -0000 1.19 +++ hunt/huntd/driver.c 28 Aug 2013 14:51:36 -0000 @@ -466,9 +466,6 @@ init(int background) if (Server_socket + 1 > Num_fds) Num_fds = Server_socket + 1; - /* Initialise the random seed: */ - srandomdev(); - /* Dig the maze: */ makemaze(); @@ -916,9 +913,7 @@ int rand_num(range) int range; { - if (range == 0) - return 0; - return (random() % range); + return (arc4random_uniform(range)); } /* Index: mille/mille.c =================================================================== RCS file: /cvs/src/games/mille/mille.c,v retrieving revision 1.18 diff -u -p -r1.18 mille.c --- mille/mille.c 27 Oct 2009 23:59:25 -0000 1.18 +++ mille/mille.c 28 Aug 2013 14:54:30 -0000 @@ -78,7 +78,6 @@ main(ac, av) leaveok(Score, TRUE); leaveok(Miles, TRUE); clearok(curscr, TRUE); - srandomdev(); cbreak(); noecho(); signal(SIGINT, rub); Index: mille/mille.h =================================================================== RCS file: /cvs/src/games/mille/mille.h,v retrieving revision 1.9 diff -u -p -r1.9 mille.h --- mille/mille.h 3 Jun 2003 03:01:40 -0000 1.9 +++ mille/mille.h 28 Aug 2013 14:54:18 -0000 @@ -154,11 +154,6 @@ # define EXTENSIONPROMPT 7 # define OVERWRITEFILEPROMPT 8 -# ifdef SYSV -# define srandom(x) srand(x) -# define random() rand() -# endif /* SYSV */ - typedef struct { bool coups[NUM_SAFE]; bool can_go; Index: mille/roll.c =================================================================== RCS file: /cvs/src/games/mille/roll.c,v retrieving revision 1.5 diff -u -p -r1.5 roll.c --- mille/roll.c 27 Oct 2009 23:59:25 -0000 1.5 +++ mille/roll.c 28 Aug 2013 14:54:44 -0000 @@ -47,6 +47,6 @@ roll(ndie, nsides) tot = 0; while (ndie--) - tot += random() % nsides + 1; + tot += arc4random_uniform(nsides) + 1; return tot; } Index: monop/monop.c =================================================================== RCS file: /cvs/src/games/monop/monop.c,v retrieving revision 1.10 diff -u -p -r1.10 monop.c --- monop/monop.c 27 Oct 2009 23:59:26 -0000 1.10 +++ monop/monop.c 28 Aug 2013 14:55:29 -0000 @@ -47,7 +47,6 @@ main(ac, av) int ac; char *av[]; { - srandomdev(); num_luck = sizeof lucky_mes / sizeof (char *); init_decks(); init_monops(); Index: monop/roll.c =================================================================== RCS file: /cvs/src/games/monop/roll.c,v retrieving revision 1.5 diff -u -p -r1.5 roll.c --- monop/roll.c 27 Oct 2009 23:59:26 -0000 1.5 +++ monop/roll.c 28 Aug 2013 14:59:11 -0000 @@ -30,6 +30,7 @@ * SUCH DAMAGE. */ +#include <stdint.h> #include <stdlib.h> /* @@ -39,12 +40,12 @@ int roll(ndie, nsides) int ndie, nsides; { - int tot, r; + int tot; double num_sides; num_sides = nsides; tot = 0; while (ndie--) - tot += (r = random()) * (num_sides / RAND_MAX) + 1; + tot += arc4random() * (num_sides / UINT32_MAX) + 1; return tot; } Index: phantasia/include.h =================================================================== RCS file: /cvs/src/games/phantasia/include.h,v retrieving revision 1.3 diff -u -p -r1.3 include.h --- phantasia/include.h 4 Feb 2001 02:51:23 -0000 1.3 +++ phantasia/include.h 28 Aug 2013 15:21:26 -0000 @@ -14,6 +14,7 @@ #include <math.h> #include <setjmp.h> #include <signal.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> #include <time.h> Index: phantasia/main.c =================================================================== RCS file: /cvs/src/games/phantasia/main.c,v retrieving revision 1.14 diff -u -p -r1.14 main.c --- phantasia/main.c 15 Dec 2010 06:40:39 -0000 1.14 +++ phantasia/main.c 28 Aug 2013 15:09:20 -0000 @@ -312,8 +312,7 @@ main(argc, argv) / / RETURN VALUE: none / -/ MODULES CALLED: time(), fopen(), srandom(), error(), getuid(), getlogin(), -/ getpwuid() +/ MODULES CALLED: fopen(), error(), getuid(), getlogin(), getpwuid() / / GLOBAL INPUTS: / @@ -384,8 +383,6 @@ initialstate() if ((Energyvoidfp = fopen(_PATH_VOID, "r+")) == NULL) error(_PATH_VOID); /* NOTREACHED */ - - srandomdev(); /* prime random numbers */ } /**/ /************************************************************************ Index: phantasia/misc.c =================================================================== RCS file: /cvs/src/games/phantasia/misc.c,v retrieving revision 1.14 diff -u -p -r1.14 misc.c --- phantasia/misc.c 15 Dec 2010 06:40:39 -0000 1.14 +++ phantasia/misc.c 28 Aug 2013 16:14:45 -0000 @@ -1574,7 +1574,7 @@ descrstatus(playerp) / / RETURN VALUE: none / -/ MODULES CALLED: random() +/ MODULES CALLED: arc4random() / / GLOBAL INPUTS: none / @@ -1583,19 +1583,13 @@ descrstatus(playerp) / DESCRIPTION: / Convert random integer from library routine into a floating / point number, and divide by the largest possible random number. -/ We mask large integers with 32767 to handle sites that return -/ 31 bit random integers. / *************************************************************************/ double drandom() { - if (sizeof(int) != 2) - /* use only low bits */ - return ((double) (random() & 0x7fff) / 32768.0); - else - return ((double) random() / 32768.0); + return ((double) arc4random() / (UINT32_MAX + 1.0)); } /**/ /************************************************************************ Index: phantasia/setup.c =================================================================== RCS file: /cvs/src/games/phantasia/setup.c,v retrieving revision 1.11 diff -u -p -r1.11 setup.c --- phantasia/setup.c 23 Jun 2011 03:14:32 -0000 1.11 +++ phantasia/setup.c 28 Aug 2013 16:14:51 -0000 @@ -25,8 +25,8 @@ void Error(char *, char *); / / RETURN VALUE: none / -/ MODULES CALLED: time(), exit(), stat(), Error(), open(), close(), fopen(), -/ fgets(), floor(), srandomdev(), umask(), strlcpy(), +/ MODULES CALLED: exit(), stat(), Error(), open(), close(), fopen(), +/ fgets(), floor(), umask(), strlcpy(), / unlink(), fwrite(), fclose(), sscanf(), printf(), strlen(), fprintf() / / GLOBAL INPUTS: Curmonster, _iob[], Databuf[], *Monstfp, Enrgyvoid @@ -82,8 +82,6 @@ main(argc, argv) argc -= optind; argv += optind; - srandomdev(); /* prime random numbers */ - umask(0117); /* only owner can read/write created files */ prefix = getenv("DESTDIR"); @@ -227,7 +225,7 @@ Error(str, file) / / RETURN VALUE: none / -/ MODULES CALLED: random() +/ MODULES CALLED: arc4random() / / GLOBAL INPUTS: none / @@ -240,8 +238,5 @@ Error(str, file) double drandom() { - if (sizeof(int) != 2) - return((double) (random() & 0x7fff) / 32768.0); - else - return((double) random() / 32768.0); + return((double) arc4random() / (UINT32_MAX + 1.0)); } Index: quiz/quiz.c =================================================================== RCS file: /cvs/src/games/quiz/quiz.c,v retrieving revision 1.20 diff -u -p -r1.20 quiz.c --- quiz/quiz.c 27 Oct 2009 23:59:26 -0000 1.20 +++ quiz/quiz.c 28 Aug 2013 15:25:59 -0000 @@ -213,12 +213,11 @@ quiz(void) char *answer, *t, question[LINE_SZ]; const char *s; - srandomdev(); guesses = rights = wrongs = 0; for (;;) { if (qsize == 0) break; - next = random() % qsize; + next = arc4random_uniform(qsize); qp = qlist.q_next; for (i = 0; i < next; i++) qp = qp->q_next; @@ -228,7 +227,7 @@ quiz(void) qsize = next; continue; } - if (tflag && random() % 100 > 20) { + if (tflag && arc4random_uniform(100) > 20) { /* repeat questions in tutorial mode */ while (qp && (!qp->q_asked || qp->q_answered)) qp = qp->q_next; Index: rain/rain.c =================================================================== RCS file: /cvs/src/games/rain/rain.c,v retrieving revision 1.16 diff -u -p -r1.16 rain.c --- rain/rain.c 27 May 2012 10:09:33 -0000 1.16 +++ rain/rain.c 28 Aug 2013 15:27:28 -0000 @@ -84,7 +84,6 @@ main(int argc, char *argv[]) sleeptime.tv_nsec = delay * 500000; timespecadd(&sleeptime, &sleeptime, &sleeptime); - srandomdev(); initscr(); tcols = COLS - 4; tlines = LINES - 4; @@ -98,16 +97,16 @@ main(int argc, char *argv[]) curs_set(0); for (j = 4; j >= 0; --j) { - xpos[j] = random() % tcols + 2; - ypos[j] = random() % tlines + 2; + xpos[j] = arc4random_uniform(tcols) + 2; + ypos[j] = arc4random_uniform(tlines) + 2; } for (j = 0;;) { if (sig_caught) { endwin(); exit(0); } - x = random() % tcols + 2; - y = random() % tlines + 2; + x = arc4random_uniform(tcols) + 2; + y = arc4random_uniform(tlines) + 2; mvaddch(y, x, '.'); mvaddch(ypos[j], xpos[j], 'o'); if (!j--) Index: robots/main.c =================================================================== RCS file: /cvs/src/games/robots/main.c,v retrieving revision 1.17 diff -u -p -r1.17 main.c --- robots/main.c 27 Oct 2009 23:59:26 -0000 1.17 +++ robots/main.c 28 Aug 2013 15:28:41 -0000 @@ -136,7 +136,6 @@ main(int ac, char *av[]) stdscr = newwin(Y_SIZE, X_SIZE, 0, 0); } - srandomdev(); do { init_field(); for (Level = Start_level; !Dead; Level++) { Index: robots/rnd_pos.c =================================================================== RCS file: /cvs/src/games/robots/rnd_pos.c,v retrieving revision 1.5 diff -u -p -r1.5 rnd_pos.c --- robots/rnd_pos.c 27 Oct 2009 23:59:26 -0000 1.5 +++ robots/rnd_pos.c 28 Aug 2013 15:29:04 -0000 @@ -55,5 +55,5 @@ rnd_pos(void) int rnd(int range) { - return (int)random() % range; + return arc4random_uniform(range); } Index: sail/extern.h =================================================================== RCS file: /cvs/src/games/sail/extern.h,v retrieving revision 1.8 diff -u -p -r1.8 extern.h --- sail/extern.h 3 Jun 2003 03:01:41 -0000 1.8 +++ sail/extern.h 28 Aug 2013 15:30:39 -0000 @@ -61,7 +61,7 @@ extern char nobells; /* -b, don't ring extern gid_t gid; extern gid_t egid; -#define die() ((random() >> 3) % 6 + 1) +#define die() (arc4random_uniform(6) + 1) #define sqr(a) ((a) * (a)) #define min(a,b) ((a) < (b) ? (a) : (b)) Index: sail/main.c =================================================================== RCS file: /cvs/src/games/sail/main.c,v retrieving revision 1.6 diff -u -p -r1.6 main.c --- sail/main.c 27 Oct 2009 23:59:27 -0000 1.6 +++ sail/main.c 28 Aug 2013 15:29:33 -0000 @@ -56,7 +56,6 @@ main(argc, argv) exit(1); close(fd); - srandomdev(); if ((p = strrchr(*argv, '/'))) p++; else Index: snake/snake.c =================================================================== RCS file: /cvs/src/games/snake/snake.c,v retrieving revision 1.14 diff -u -p -r1.14 snake.c --- snake/snake.c 13 Nov 2009 21:50:12 -0000 1.14 +++ snake/snake.c 28 Aug 2013 15:34:38 -0000 @@ -170,7 +170,6 @@ main(int argc, char *argv[]) exit(1); } - srandomdev(); penalty = loot = 0; initscr(); #ifdef KEY_LEFT @@ -470,8 +469,8 @@ snrand(struct point *sp) int i; for (;;) { - p.col = random() % ccnt; - p.line = random() % lcnt; + p.col = arc4random_uniform(ccnt); + p.line = arc4random_uniform(lcnt); /* make sure it's not on top of something else */ if (p.line == 0 && p.col < 5) @@ -580,7 +579,7 @@ chase(struct point *np, struct point *sp } for (w = i = 0; i < 8; i++) w += wt[i]; - vp = ((random() >> 6) & 01777) % w; + vp = arc4random_uniform(w); for (i = 0; i < 8; i++) if (vp < wt[i]) break; @@ -830,7 +829,7 @@ pushsnake(void) if ((same(&snake[i], &you)) || (same(&tmp, &you))) { surround(&you); i = (cashvalue) % 10; - bonus = ((random() >> 8) & 0377) % 10; + bonus = arc4random_uniform(10); mvprintw(lcnt + 1, 0, "%d\n", bonus); refresh(); delay(30); Index: tetris/tetris.c =================================================================== RCS file: /cvs/src/games/tetris/tetris.c,v retrieving revision 1.23 diff -u -p -r1.23 tetris.c --- tetris/tetris.c 28 Oct 2009 00:25:38 -0000 1.23 +++ tetris/tetris.c 28 Aug 2013 15:41:05 -0000 @@ -139,8 +139,8 @@ randshape(void) const struct shape *tmp; int i, j; - tmp = &shapes[random() % 7]; - j = random() % 4; + tmp = &shapes[arc4random_uniform(7)]; + j = arc4random_uniform(4); for (i = 0; i < j; i++) tmp = &shapes[classic? tmp->rotc : tmp->rot]; return (tmp); @@ -225,7 +225,6 @@ main(int argc, char *argv[]) scr_init(); setup_board(); - srandomdev(); scr_set(); pos = A_FIRST*B_COLS + (B_COLS/2)-1; Index: worm/worm.c =================================================================== RCS file: /cvs/src/games/worm/worm.c,v retrieving revision 1.23 diff -u -p -r1.23 worm.c --- worm/worm.c 27 Oct 2009 23:59:27 -0000 1.23 +++ worm/worm.c 28 Aug 2013 15:49:16 -0000 @@ -92,7 +92,6 @@ main(int argc, char **argv) FD_ZERO(&rset); setbuf(stdout, outbuf); - srandomdev(); signal(SIGINT, leave); signal(SIGQUIT, leave); signal(SIGTSTP, suspend); /* process control signal */ @@ -209,7 +208,7 @@ leave(int dummy) int rnd(int range) { - return random() % range; + return arc4random_uniform(range); } void Index: worms/worms.c =================================================================== RCS file: /cvs/src/games/worms/worms.c,v retrieving revision 1.20 diff -u -p -r1.20 worms.c --- worms/worms.c 25 Apr 2011 13:30:07 -0000 1.20 +++ worms/worms.c 28 Aug 2013 15:50:03 -0000 @@ -226,7 +226,6 @@ main(int argc, char *argv[]) sleeptime.tv_nsec = delay * 500000; timespecadd(&sleeptime, &sleeptime, &sleeptime); - srandomdev(); if (!(worm = calloc((size_t)number, sizeof(struct worm)))) nomem(); initscr(); @@ -319,7 +318,7 @@ main(int argc, char *argv[]) break; default: w->orientation = - op->opts[(int)random() % op->nopts]; + op->opts[arc4random_uniform(op->nopts)]; } mvaddch(y += yinc[w->orientation], x += xinc[w->orientation], Index: wump/wump.c =================================================================== RCS file: /cvs/src/games/wump/wump.c,v retrieving revision 1.25 diff -u -p -r1.25 wump.c --- wump/wump.c 27 Oct 2009 23:59:28 -0000 1.25 +++ wump/wump.c 28 Aug 2013 16:05:20 -0000 @@ -201,12 +201,11 @@ main(int argc, char *argv[]) errx(1, "too many tunnels! The cave collapsed!\n(Fortunately, the wumpus escaped!)"); - srandomdev(); if (level == HARD) { if (room_num / 2 - bat_num) - bat_num += (random() % (room_num / 2 - bat_num)); + bat_num += arc4random_uniform(room_num / 2 - bat_num); if (room_num / 2 - pit_num) - pit_num += (random() % (room_num / 2 - pit_num)); + pit_num += arc4random_uniform(room_num / 2 - pit_num); } /* Leave at least two rooms free--one for the player to start in, and @@ -314,7 +313,7 @@ take_action(void) case '\n': return(0); } - if (random() % 15 == 1) + if (arc4random_uniform(15) == 1) (void)printf("Que pasa?\n"); else (void)printf("I don't understand!\n"); @@ -367,7 +366,7 @@ move_to(const char *room_number) if (!tunnel_available) { (void)printf("*Oof!* (You hit the wall)\n"); - if (random() % 6 == 1) { + if (arc4random_uniform(6) == 1) { (void)printf("Your colorful comments awaken the wumpus!\n"); move_wump(); if (wumpus_loc == player_loc) { @@ -380,7 +379,7 @@ move_to(const char *room_number) /* now let's move into that room and check it out for dangers */ /* if (next_room == room_num + 1) - * jump(next_room = (random() % room_num) + 1); + * jump(next_room = arc4random_uniform(room_num) + 1); */ player_loc = next_room; for (;;) { @@ -392,7 +391,7 @@ move_to(const char *room_number) return(1); } if (cave[next_room].has_a_pit) { - if (random() % 12 < 2) { + if (arc4random_uniform(12) < 2) { pit_survive(); return(0); } else { @@ -408,7 +407,8 @@ move_to(const char *room_number) (void)printf( "*flap* *flap* *flap* (humongous bats pick you up and move you%s!)\n", just_moved_by_bats ? " again": ""); - next_room = player_loc = (random() % room_num) + 1; + next_room = player_loc = + arc4random_uniform(room_num) + 1; just_moved_by_bats = 1; } @@ -461,7 +461,7 @@ shoot(char *room_list) if (next == 0) break; /* Old wumpus used room 0 as the terminator */ - chance = random() % 10; + chance = arc4random_uniform(10); if (roomcnt == 4 && chance < 2) { (void)printf( "Your finger slips on the bowstring! *twaaaaaang*\n\ @@ -482,11 +482,12 @@ The arrow is weakly shot and can go no f /* if (next > room_num) { * (void)printf( * "A faint gleam tells you the arrow has gone through a magic tunnel!\n"); - * arrow_location = (random() % room_num) + 1; + * arrow_location = + * arc4random_uniform(room_num) + 1; * } else */ arrow_location = next; } else { - link = (random() % link_num); + link = (arc4random_uniform(link_num)); if (cave[arrow_location].tunnel[link] == player_loc) (void)printf( "*thunk* The arrow can't find a way from %d to %d and flies back into\n\ @@ -529,11 +530,13 @@ into room %d!\n", arrow_location, next, /* each time you shoot, it's more likely the wumpus moves */ static int lastchance = 2; - if (random() % level == EASY ? 12 : 9 < (lastchance += 2)) { + if (arc4random_uniform(level) == EASY ? + 12 : 9 < (lastchance += 2)) { move_wump(); if (wumpus_loc == player_loc) { wump_walk_kill(); - lastchance = random() % 3; /* Reset for next game */ + /* Reset for next game */ + lastchance = arc4random_uniform(3); return(1); } @@ -587,7 +590,7 @@ cave_init(void) * divisor of (delta + 1) and room_num to be 1 */ do { - delta = (random() % (room_num - 1)) + 1; + delta = arc4random_uniform(room_num - 1) + 1; } while (gcd(room_num, delta + 1) != 1); for (i = 1; i <= room_num; ++i) { @@ -602,7 +605,7 @@ cave_init(void) for (j = 2; j < link_num ; j++) { if (cave[i].tunnel[j] != -1) continue; -try_again: link = (random() % room_num) + 1; +try_again: link = arc4random_uniform(room_num) + 1; /* skip duplicates */ for (k = 0; k < j; k++) if (cave[i].tunnel[k] == link) @@ -611,7 +614,7 @@ try_again: link = (random() % room_num) if (link == i) goto try_again; cave[i].tunnel[j] = link; - if (random() % 2 == 1) + if (arc4random() % 2 == 1) continue; for (k = 0; k < link_num; ++k) { /* if duplicate, skip it */ @@ -678,7 +681,7 @@ dodecahedral_cave_init(void) for (i = 0; i < 20; i++) loc[i] = i; for (i = 0; i < 20; i++) { - j = random() % (20 - i); + j = arc4random_uniform(20 - i); if (j) { temp = loc[i]; loc[i] = loc[i + j]; @@ -731,7 +734,7 @@ initialize_things_in_cave(void) /* place some bats, pits, the wumpus, and the player. */ for (i = 0; i < bat_num; ++i) { do { - loc = (random() % room_num) + 1; + loc = arc4random_uniform(room_num) + 1; } while (cave[loc].has_a_bat); cave[loc].has_a_bat = 1; #ifdef DEBUG @@ -742,7 +745,7 @@ initialize_things_in_cave(void) for (i = 0; i < pit_num; ++i) { do { - loc = (random() % room_num) + 1; + loc = arc4random_uniform(room_num) + 1; } while (cave[loc].has_a_pit || cave[loc].has_a_bat); /* Above used to be &&; || makes sense but so does just * checking cave[loc].has_a_pit */ @@ -753,14 +756,14 @@ initialize_things_in_cave(void) #endif } - wumpus_loc = (random() % room_num) + 1; + wumpus_loc = arc4random_uniform(room_num) + 1; #ifdef DEBUG if (debug) (void)printf("<wumpus in room %d>\n", wumpus_loc); #endif do { - player_loc = (random() % room_num) + 1; + player_loc = arc4random_uniform(room_num) + 1; } while (player_loc == wumpus_loc || cave[player_loc].has_a_pit || cave[player_loc].has_a_bat); /* Replaced (level == HARD ? @@ -839,7 +842,7 @@ wump_nearby(void) void move_wump(void) { - wumpus_loc = cave[wumpus_loc].tunnel[random() % link_num]; + wumpus_loc = cave[wumpus_loc].tunnel[arc4random_uniform(link_num)]; #ifdef DEBUG if (debug) (void)printf("Wumpus moved to room %d\n",wumpus_loc); -- Christian "naddy" Weisgerber na...@mips.inka.de