ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/random.h
Revision: 2.19
Committed: Mon Jan 26 20:04:30 2015 UTC (9 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.18: +3 -1 lines
Log Message:
Added needed include file for rand() and RAND_MAX under Windows

File Contents

# Content
1 /* RCSid $Id: random.h,v 2.18 2011/04/09 15:39:16 greg Exp $ */
2 /*
3 * random.h - header file for random(3) and urand() function.
4 */
5 #ifndef _RAD_RANDOM_H_
6 #define _RAD_RANDOM_H_
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10
11 #ifdef _WIN32
12
13 #include <stdlib.h>
14
15 #if (RAND_MAX <= 65536)
16 #define random() ((long)rand()<<16^(long)rand()<<6^(long)rand()>>4)
17 #else
18 #define random() rand()
19 #endif
20 #define srandom(s) srand((unsigned)(s))
21
22 #define frandom() (rand()*(1./(RAND_MAX+.5)))
23
24 #else
25 #ifdef BSD
26
27 extern long random();
28
29 #define frandom() (random()*(1./2147483648.))
30
31 #else
32
33 extern long lrand48();
34 extern double drand48();
35
36 #define random() lrand48()
37 #define srandom(s) srand48((long)(s))
38 #define frandom() drand48()
39
40 #endif
41 #endif
42
43 extern unsigned short *urperm;
44 extern int urmask;
45
46 #define urand(i) (urmask ? (urperm[(i)&urmask]+frandom())/(urmask+1) \
47 : frandom())
48
49 extern int initurand(int size);
50
51 /* defined in urand.c */
52 extern int ilhash(int *d, int n);
53 /* defined in urind.c */
54 extern int urind(int s, int i);
55 /* defined in multisamp.c */
56 extern void multisamp(double t[], int n, double r);
57
58
59 #ifdef __cplusplus
60 }
61 #endif
62 #endif /* _RAD_RANDOM_H_ */
63