ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/urand.c
Revision: 1.3
Committed: Tue May 21 11:01:00 1991 UTC (32 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.2: +2 -3 lines
Log Message:
added hash function

File Contents

# Content
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 }
48
49
50 int
51 ilhash(d, n) /* hash a set of integer values */
52 register int *d;
53 register int n;
54 {
55 static int tab[8] = {13623,353,1637,5831,2314,3887,5832,8737};
56 register unsigned hval;
57
58 hval = 0;
59 while (n-- > 0)
60 hval += *d++ * tab[n&7];
61 return(hval);
62 }