Back to index

radiance  4R0+20100331
random.h
Go to the documentation of this file.
00001 /* RCSid $Id: random.h,v 2.17 2006/04/05 15:21:53 greg Exp $ */
00002 /*
00003  *  random.h - header file for random(3) and urand() function.
00004  */
00005 #ifndef _RAD_RANDOM_H_
00006 #define _RAD_RANDOM_H_
00007 #ifdef __cplusplus
00008 extern "C" {
00009 #endif
00010 
00011 #ifdef _WIN32
00012 
00013 #if (RAND_MAX <= 65536)
00014 #define random()     ((long)rand()<<16^(long)rand()<<6^(long)rand()>>4)
00015 #else
00016 #define random()     rand()
00017 #endif
00018 #define srandom(s)   srand((unsigned)(s))
00019 
00020 #define frandom()    (rand()*(1./RAND_MAX))
00021 
00022 #else
00023 #ifdef BSD
00024 
00025 extern long  random();
00026 
00027 #define        frandom()    (random()*(1./2147483648.))
00028 
00029 #else
00030 
00031 extern long  lrand48();
00032 extern double  drand48();
00033 
00034 #define        random()     lrand48()
00035 #define  srandom(s)  srand48((long)(s))
00036 #define        frandom()    drand48()
00037 
00038 #endif
00039 #endif
00040 
00041 extern unsigned short       *urperm;
00042 extern int    urmask;
00043 
00044 #define        urand(i)     (urmask ? (urperm[(i)&urmask]+frandom())/(urmask+1) \
00045                             : frandom())
00046 
00047 extern int    initurand(int size);
00048 
00049                             /* defined in urand.c */
00050 extern int    ilhash(int *d, int n);
00051                             /* defined in urind.c */
00052 extern int    urind(int s, int i);
00053                             /* defined in multisamp.c */
00054 extern void   multisamp(double t[], int n, double r);
00055 
00056 
00057 #ifdef __cplusplus
00058 }
00059 #endif
00060 #endif /* _RAD_RANDOM_H_ */
00061