ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/urand.c
Revision: 2.3
Committed: Mon Dec 1 09:55:00 1997 UTC (26 years, 5 months ago) by gregl
Content type: text/plain
Branch: MAIN
Changes since 2.2: +4 -2 lines
Log Message:
added define to eliminate initurand() reference for -DMC

File Contents

# User Rev Content
1 gregl 2.3 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2 greg 1.1
3     #ifndef lint
4 gregl 2.3 static char SCCSid[] = "$SunId$ SGI";
5 greg 1.1 #endif
6    
7     /*
8 greg 1.5 * Anticorrelated random function due to Christophe Schlick
9 greg 1.1 */
10    
11     #include "random.h"
12    
13     #define NULL 0
14    
15     extern char *malloc();
16    
17 greg 2.2 short *urperm = NULL; /* urand() permutation */
18 greg 1.1 int urmask; /* bits used in permutation */
19    
20    
21 gregl 2.3 int
22 greg 1.1 initurand(size) /* initialize urand() for size entries */
23     int size;
24     {
25     int order, n;
26     register int i, offset;
27    
28 greg 2.2 if (urperm != NULL)
29     free((char *)urperm);
30 greg 1.1 size--;
31     for (i = 1; size >>= 1; i++)
32     ;
33     order = i;
34     urmask = (1<<i) - 1;
35     urperm = (short *)malloc((urmask+1)*sizeof(short));
36     if (urperm == NULL) {
37     eputs("out of memory in initurand\n");
38     quit(1);
39     }
40     urperm[0] = 0;
41     for (n = 1, offset = 1; n <= order; n++, offset <<= 1)
42     for (i = offset; i--; ) {
43     urperm[i] =
44     urperm[i+offset] = 2*urperm[i];
45     if (random() & 0x4000)
46     urperm[i]++;
47     else
48     urperm[i+offset]++;
49     }
50 gregl 2.3 return(1<<order);
51 greg 1.2 }
52    
53    
54     int
55 greg 1.3 ilhash(d, n) /* hash a set of integer values */
56 greg 1.2 register int *d;
57     register int n;
58     {
59     static int tab[8] = {13623,353,1637,5831,2314,3887,5832,8737};
60 greg 1.4 register int hval;
61 greg 1.2
62     hval = 0;
63     while (n-- > 0)
64     hval += *d++ * tab[n&7];
65 greg 1.3 return(hval);
66 greg 1.1 }