--- ray/src/common/urand.c 1991/05/17 12:55:27 1.1 +++ ray/src/common/urand.c 1992/09/05 13:40:55 2.2 @@ -1,11 +1,11 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; #endif /* - * Uncorrelated (anticorrelated) random function + * Anticorrelated random function due to Christophe Schlick */ #include "random.h" @@ -14,7 +14,7 @@ static char SCCSid[] = "$SunId$ LBL"; extern char *malloc(); -short *urperm; /* urand() permutation */ +short *urperm = NULL; /* urand() permutation */ int urmask; /* bits used in permutation */ @@ -24,6 +24,8 @@ int size; int order, n; register int i, offset; + if (urperm != NULL) + free((char *)urperm); size--; for (i = 1; size >>= 1; i++) ; @@ -44,4 +46,19 @@ int size; else urperm[i+offset]++; } +} + + +int +ilhash(d, n) /* hash a set of integer values */ +register int *d; +register int n; +{ + static int tab[8] = {13623,353,1637,5831,2314,3887,5832,8737}; + register int hval; + + hval = 0; + while (n-- > 0) + hval += *d++ * tab[n&7]; + return(hval); }