Author: cem
Date: Fri Dec 13 04:48:20 2019
New Revision: 355694
URL: https://svnweb.freebsd.org/changeset/base/355694

Log:
  kern/subr_unit: Rip srandomdev, random(3) out of dead code
  
  The simulation cannot be reproduced, so the value of using a deterministic 
PRNG
  like random(3) is dubious.  The number of repitions used in the sample isn't a
  problem for the Chacha implementation of arc4random we have today.  (Also, no
  one actually runs this code; it was provided as an example of the work the
  author did validating the implementation.  It's not even test code.)

Modified:
  head/sys/kern/subr_unit.c

Modified: head/sys/kern/subr_unit.c
==============================================================================
--- head/sys/kern/subr_unit.c   Fri Dec 13 04:37:39 2019        (r355693)
+++ head/sys/kern/subr_unit.c   Fri Dec 13 04:48:20 2019        (r355694)
@@ -1021,7 +1021,7 @@ main(int argc, char **argv)
        long count = 10000;     /* Number of unrs to test */
        long reps = 1, m;
        int ch;
-       u_int i, j;
+       u_int i;
 
        verbose = false;
 
@@ -1055,20 +1055,18 @@ main(int argc, char **argv)
        a = calloc(count, sizeof(char));
        if (a == NULL)
                err(1, "calloc failed");
-       srandomdev();
 
        printf("sizeof(struct unr) %zu\n", sizeof(struct unr));
        printf("sizeof(struct unrb) %zu\n", sizeof(struct unrb));
        printf("sizeof(struct unrhdr) %zu\n", sizeof(struct unrhdr));
        printf("NBITS %lu\n", (unsigned long)NBITS);
        for (m = 0; m < count * reps; m++) {
-               j = random();
-               i = (j >> 1) % count;
+               i = arc4random_uniform(count);
 #if 0
                if (a[i] && (j & 1))
                        continue;
 #endif
-               if ((random() & 1) != 0)
+               if ((arc4random() & 1) != 0)
                        test_alloc_unr(uh, i, a);
                else
                        test_alloc_unr_specific(uh, i, a);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to