--- ray/src/common/urand.c 1991/11/12 16:55:47 2.1 +++ ray/src/common/urand.c 2004/05/16 14:49:42 2.9 @@ -1,35 +1,44 @@ -/* 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.9 2004/05/16 14:49:42 greg Exp $"; #endif - /* * Anticorrelated random function due to Christophe Schlick */ +#include "copyright.h" + +#include + +#include "standard.h" #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--; - for (i = 1; size >>= 1; i++) - ; + if (urperm != NULL) + free((void *)urperm); + if (--size <= 0) { + urperm = NULL; + urmask = 0; + return(0); + } + for (i = 1; (size >>= 1); i++) + if (i == MAXORDER) + break; order = i; - urmask = (1<