--- ray/src/common/urand.c 1998/01/05 16:47:37 2.4 +++ ray/src/common/urand.c 2006/04/05 06:22:56 2.10 @@ -1,25 +1,26 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: urand.c,v 2.10 2006/04/05 06:22:56 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 #define MAXORDER (8*sizeof(unsigned short)) -extern char *malloc(); +static unsigned short empty_tab = 0; -unsigned short *urperm = NULL; /* urand() permutation */ -int urmask; /* bits used in permutation */ +unsigned short *urperm = &empty_tab; /* urand() permutation */ +int urmask = 0; /* bits used in permutation */ - int initurand(size) /* initialize urand() for size entries */ int size; @@ -27,13 +28,19 @@ int size; int order, n; register int i, offset; - if (urperm != NULL) - free((char *)urperm); - size--; - 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); }