--- ray/src/cal/cnt.c 2022/04/20 20:56:01 1.5 +++ ray/src/cal/cnt.c 2022/04/22 15:52:50 1.8 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: cnt.c,v 1.5 2022/04/20 20:56:01 greg Exp $"; +static const char RCSid[] = "$Id: cnt.c,v 1.8 2022/04/22 15:52:50 greg Exp $"; #endif /* * cnt.c - simple counting program. @@ -161,9 +161,11 @@ incr_counter(uby8 *ctrp, int n) { n = tree_br[n].cntr_siz; - while (n-- > 0) /* LSB first */ - if (++(*ctrp++)) - break; + while (! ++(*ctrp++)) /* LSB first */ + if (--n <= 0) { + fputs("Shuffle occupancy overflow!\n", stderr); + exit(1); /* means we sized something wrong */ + } } @@ -213,7 +215,7 @@ big_shuffle(long *n, long alen) tree_root = tree_alloc(alen); while (alen > 0) /* allocate and print random array entries */ - print_shuf(n, eat_nth_leaf(tree_root, random() % alen--)); + print_shuf(n, eat_nth_leaf(tree_root, irandom(alen--))); free(tree_root); /* all done */ } @@ -251,7 +253,7 @@ shuffle(long *n) myshuf[i] = i; /* perform Fisher-Yates shuffle */ for (i = 0; i < alen-1; i++) { - int ix = random()%(alen-i) + i; + int ix = irandom(alen-i) + i; int ndx = myshuf[i]; myshuf[i] = myshuf[ix]; myshuf[ix] = ndx;