> Date: Wed, 25 Nov 2015 20:44:31 +0000 > From: Ricardo Mestre <ser...@helheim.mooo.com> > > While checking if there was still a score file on trek(6) I found that it was > still using random(), and inspired by the code on NetBSD and OpenBSD relevant > manpages I came up with this diff. Let's bring trek(6) to the 21st century, at > least here :) Does it look good?
You missed the srandom_deterministic() call. After studying that bit of code, you might want to reconsider your diff. > Index: trek.h > =================================================================== > RCS file: /cvs/src/games/trek/trek.h,v > retrieving revision 1.13 > diff -u -p -u -r1.13 trek.h > --- trek.h 2 Jun 2013 04:28:39 -0000 1.13 > +++ trek.h 25 Nov 2015 20:19:14 -0000 > @@ -50,6 +50,8 @@ > ** actually allocate stuff in "externs.c" > */ > > +#include <sys/types.h> > + > /********************* GALAXY **************************/ > > /* galactic parameters */ > @@ -473,7 +475,7 @@ void play(void); > void ram(int, int ); > > /* ranf.c */ > -int ranf(int); > +uint32_t ranf(uint32_t); > double franf(void); > > /* rest.c */ > Index: ranf.c > =================================================================== > RCS file: /cvs/src/games/trek/ranf.c,v > retrieving revision 1.5 > diff -u -p -u -r1.5 ranf.c > --- ranf.c 27 Oct 2009 23:59:27 -0000 1.5 > +++ ranf.c 25 Nov 2015 20:19:47 -0000 > @@ -33,23 +33,17 @@ > #include <stdio.h> > #include <stdlib.h> > > -int > -ranf(max) > - int max; > +uint32_t > +ranf(uint32_t max) > { > - int t; > - > if (max <= 0) > return (0); > - t = random() >> 5; > - return (t % max); > + return (arc4random_uniform(max)); > } > > > double > franf() > { > - double t; > - t = random() & 077777; > - return (t / 32767.0); > + return ((double)(arc4random() / RAND_MAX)); > } > >