--- ray/src/common/urand.c 1998/01/05 16:47:37 2.4 +++ ray/src/common/urand.c 2003/06/07 12:50:21 2.7 @@ -1,25 +1,24 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: urand.c,v 2.7 2003/06/07 12:50:21 schorsch 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(); - unsigned short *urperm = NULL; /* urand() permutation */ int urmask; /* bits used in permutation */ - int initurand(size) /* initialize urand() for size entries */ int size; @@ -28,8 +27,12 @@ int size; register int i, offset; if (urperm != NULL) - free((char *)urperm); - size--; + free((void *)urperm); + if (--size <= 0) { + urperm = NULL; + urmask = 0; + return(0); + } for (i = 1; size >>= 1; i++) ; order = i>MAXORDER ? MAXORDER : i;