ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/random.h
Revision: 2.18
Committed: Sat Apr 9 15:39:16 2011 UTC (13 years ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad4R2P2, rad4R2, rad4R1, rad4R2P1
Changes since 2.17: +2 -2 lines
Log Message:
Fixed range of rand() -> double conversion

File Contents

# Content
1 /* RCSid $Id: random.h,v 2.17 2006/04/05 15:21:53 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 #if (RAND_MAX <= 65536)
14 #define random() ((long)rand()<<16^(long)rand()<<6^(long)rand()>>4)
15 #else
16 #define random() rand()
17 #endif
18 #define srandom(s) srand((unsigned)(s))
19
20 #define frandom() (rand()*(1./(RAND_MAX+.5)))
21
22 #else
23 #ifdef BSD
24
25 extern long random();
26
27 #define frandom() (random()*(1./2147483648.))
28
29 #else
30
31 extern long lrand48();
32 extern double drand48();
33
34 #define random() lrand48()
35 #define srandom(s) srand48((long)(s))
36 #define frandom() drand48()
37
38 #endif
39 #endif
40
41 extern unsigned short *urperm;
42 extern int urmask;
43
44 #define urand(i) (urmask ? (urperm[(i)&urmask]+frandom())/(urmask+1) \
45 : frandom())
46
47 extern int initurand(int size);
48
49 /* defined in urand.c */
50 extern int ilhash(int *d, int n);
51 /* defined in urind.c */
52 extern int urind(int s, int i);
53 /* defined in multisamp.c */
54 extern void multisamp(double t[], int n, double r);
55
56
57 #ifdef __cplusplus
58 }
59 #endif
60 #endif /* _RAD_RANDOM_H_ */
61