--- ray/src/common/urand.c 1991/05/17 12:55:27 1.1 +++ ray/src/common/urand.c 2003/02/25 02:47:22 2.6 @@ -1,35 +1,41 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: urand.c,v 2.6 2003/02/25 02:47:22 greg Exp $"; #endif - /* - * Uncorrelated (anticorrelated) random function + * Anticorrelated random function due to Christophe Schlick */ +#include "copyright.h" + +#include #include "random.h" -#define NULL 0 +#undef initurand -extern char *malloc(); +#define MAXORDER (8*sizeof(unsigned short)) -short *urperm; /* urand() permutation */ +unsigned short *urperm = NULL; /* urand() permutation */ int urmask; /* bits used in permutation */ - +int initurand(size) /* initialize urand() for size entries */ int size; { int order, n; register int i, offset; - size--; + if (urperm != NULL) + free((void *)urperm); + if (--size <= 0) { + urperm = NULL; + urmask = 0; + return(0); + } for (i = 1; size >>= 1; i++) ; - order = i; + order = i>MAXORDER ? MAXORDER : i; urmask = (1< 0) + hval += *d++ * tab[n&7]; + return(hval); }