After consultation with the C standard, deraadt and I have determined
that some speedups can be made the to algorithm used by rand().

Theo initially proposed seed++, but I think seed-- is less expected
and therefore makes a better random number generator.

Index: rand.c
===================================================================
RCS file: /cvs/src/lib/libc/stdlib/rand.c,v
retrieving revision 1.10
diff -u -p -r1.10 rand.c
--- rand.c      1 Aug 2013 19:42:08 -0000       1.10
+++ rand.c      4 Dec 2014 22:04:58 -0000
@@ -35,7 +35,7 @@ static u_int next = 1;
 int
 rand_r(u_int *seed)
 {
-       *seed = *seed * 1103515245 + 12345;
+       (*seed)--;
        return (*seed % ((u_int)RAND_MAX + 1));
 }
 

Reply via email to