--- ray/src/common/urand.c 2003/06/07 12:50:21 2.7 +++ ray/src/common/urand.c 2015/05/27 08:42:06 2.11 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: urand.c,v 2.7 2003/06/07 12:50:21 schorsch Exp $"; +static const char RCSid[] = "$Id: urand.c,v 2.11 2015/05/27 08:42:06 greg Exp $"; #endif /* * Anticorrelated random function due to Christophe Schlick @@ -7,8 +7,6 @@ static const char RCSid[] = "$Id: urand.c,v 2.7 2003/0 #include "copyright.h" -#include - #include "standard.h" #include "random.h" @@ -16,27 +14,33 @@ static const char RCSid[] = "$Id: urand.c,v 2.7 2003/0 #define MAXORDER (8*sizeof(unsigned short)) -unsigned short *urperm = NULL; /* urand() permutation */ -int urmask; /* bits used in permutation */ +static unsigned short empty_tab = 0; +unsigned short *urperm = &empty_tab; /* urand() permutation */ +int urmask = 0; /* bits used in permutation */ + + int -initurand(size) /* initialize urand() for size entries */ -int size; +initurand( /* initialize urand() for size entries */ + int size +) { int order, n; - register int i, offset; + int i, offset; - if (urperm != NULL) + if ((urperm != NULL) & (urperm != &empty_tab)) free((void *)urperm); if (--size <= 0) { - urperm = NULL; + empty_tab = 0; + urperm = &empty_tab; urmask = 0; return(0); } - for (i = 1; size >>= 1; i++) - ; - order = i>MAXORDER ? MAXORDER : i; - urmask = (1<>= 1); i++) + if (i == MAXORDER) + break; + order = i; + urmask = (1< 0) - hval += *d++ * tab[n&7]; - return(hval); + hval ^= *d++ * tab[n&7]; + return(hval & 0x7fffffff); }