ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/random.h
Revision: 2.20
Committed: Wed May 27 08:37:26 2015 UTC (8 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.19: +2 -10 lines
Log Message:
Make drand48() the standard random number generator even with -DBSD

File Contents

# Content
1 /* RCSid $Id: random.h,v 2.19 2015/01/26 20:04:30 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
26 extern long lrand48();
27 extern double drand48();
28
29 #define random() lrand48()
30 #define srandom(s) srand48((long)(s))
31 #define frandom() drand48()
32
33 #endif
34
35 extern unsigned short *urperm;
36 extern int urmask;
37
38 #define urand(i) (urmask ? (urperm[(i)&urmask]+frandom())/(urmask+1.) \
39 : frandom())
40
41 extern int initurand(int size);
42
43 /* defined in urand.c */
44 extern int ilhash(int *d, int n);
45 /* defined in urind.c */
46 extern int urind(int s, int i);
47 /* defined in multisamp.c */
48 extern void multisamp(double t[], int n, double r);
49
50
51 #ifdef __cplusplus
52 }
53 #endif
54 #endif /* _RAD_RANDOM_H_ */
55