ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/urand.c
Revision: 1.1
Committed: Fri May 17 12:55:27 1991 UTC (32 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1991 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * Uncorrelated (anticorrelated) random function
9     */
10    
11     #include "random.h"
12    
13     #define NULL 0
14    
15     extern char *malloc();
16    
17     short *urperm; /* urand() permutation */
18     int urmask; /* bits used in permutation */
19    
20    
21     initurand(size) /* initialize urand() for size entries */
22     int size;
23     {
24     int order, n;
25     register int i, offset;
26    
27     size--;
28     for (i = 1; size >>= 1; i++)
29     ;
30     order = i;
31     urmask = (1<<i) - 1;
32     urperm = (short *)malloc((urmask+1)*sizeof(short));
33     if (urperm == NULL) {
34     eputs("out of memory in initurand\n");
35     quit(1);
36     }
37     urperm[0] = 0;
38     for (n = 1, offset = 1; n <= order; n++, offset <<= 1)
39     for (i = offset; i--; ) {
40     urperm[i] =
41     urperm[i+offset] = 2*urperm[i];
42     if (random() & 0x4000)
43     urperm[i]++;
44     else
45     urperm[i+offset]++;
46     }
47     }