--- ray/src/common/random.h 1992/09/21 12:02:27 2.2 +++ ray/src/common/random.h 2003/06/29 16:51:48 2.14 @@ -1,20 +1,37 @@ -/* Copyright (c) 1992 Regents of the University of California */ - -/* SCCSid "$SunId$ LBL" */ - +/* RCSid $Id: random.h,v 2.14 2003/06/29 16:51:48 greg Exp $ */ /* * random.h - header file for random(3) and urand() function. - * - * 10/1/85 */ +#ifndef _RAD_RANDOM_H_ +#define _RAD_RANDOM_H_ +#ifdef __cplusplus +extern "C" { +#endif -#ifdef MSDOS +#ifdef NORANDOM -#define random rand +#undef random +#define random() 1073741820 +#undef srandom +#define srandom(s) (s) +#define frandom() 0.5 +#define urand(i) 0.5 +#define initurand(n) (n) -#define frandom() (rand()*(1./32768.)) +#else /* ! NORANDOM */ +#ifdef _WIN32 + +#if (RAND_MAX <= 65536) +#define random() ((long)rand()<<16^(long)rand()<<6^(long)rand()>>4) #else +#define random() rand() +#endif +#define srandom(s) srand((unsigned)(s)) + +#define frandom() (rand()*(1./RAND_MAX)) + +#else #ifdef BSD extern long random(); @@ -27,12 +44,40 @@ extern long lrand48(); extern double drand48(); #define random() lrand48() +#define srandom(s) srand48((long)(s)) #define frandom() drand48() #endif #endif +#ifdef MC + +#define urand(i) frandom() +#define initurand(n) (n) + +#else /* ! MC */ + +extern unsigned short *urperm; +extern int urmask; + #define urand(i) ((urperm[(i)&urmask]+frandom())/(urmask+1)) -extern short *urperm; -extern int urmask; +extern int initurand(int size); + +#endif /* ! MC */ + +#endif /* ! NORANDOM */ + + /* defined in urand.c */ +extern int ilhash(int *d, int n); + /* defined in urind.c */ +extern int urind(int s, int i); + /* defined in multisamp.c */ +extern void multisamp(double t[], int n, double r); + + +#ifdef __cplusplus +} +#endif +#endif /* _RAD_RANDOM_H_ */ +