ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/urand.c
(Generate patch)

Comparing ray/src/common/urand.c (file contents):
Revision 2.3 by gregl, Mon Dec 1 09:55:00 1997 UTC vs.
Revision 2.7 by schorsch, Sat Jun 7 12:50:21 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Anticorrelated random function due to Christophe Schlick
6   */
7  
8 + #include "copyright.h"
9 +
10 + #include  <stdlib.h>
11 +
12 + #include  "standard.h"
13   #include  "random.h"
14  
15 < #define  NULL           0
15 > #undef initurand
16  
17 < extern char  *malloc();
17 > #define  MAXORDER       (8*sizeof(unsigned short))
18  
19 < short  *urperm = NULL;  /* urand() permutation */
19 > unsigned short  *urperm = NULL; /* urand() permutation */
20   int  urmask;            /* bits used in permutation */
21  
20
22   int
23   initurand(size)         /* initialize urand() for size entries */
24   int  size;
# Line 26 | Line 27 | int  size;
27          register int  i, offset;
28  
29          if (urperm != NULL)
30 <                free((char *)urperm);
31 <        size--;
30 >                free((void *)urperm);
31 >        if (--size <= 0) {
32 >                urperm = NULL;
33 >                urmask = 0;
34 >                return(0);
35 >        }
36          for (i = 1; size >>= 1; i++)
37                  ;
38 <        order = i;
38 >        order = i>MAXORDER ? MAXORDER : i;
39          urmask = (1<<i) - 1;
40 <        urperm = (short *)malloc((urmask+1)*sizeof(short));
40 >        urperm = (unsigned short *)malloc((urmask+1)*sizeof(unsigned short));
41          if (urperm == NULL) {
42                  eputs("out of memory in initurand\n");
43                  quit(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines