--- ray/src/common/random.h 1994/06/09 16:40:53 2.3 +++ ray/src/common/random.h 2006/04/05 06:22:56 2.16 @@ -1,18 +1,23 @@ -/* Copyright (c) 1992 Regents of the University of California */ - -/* SCCSid "$SunId$ LBL" */ - +/* RCSid $Id: random.h,v 2.16 2006/04/05 06:22:56 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 _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./32768.)) +#define frandom() (rand()*(1./RAND_MAX)) #else #ifdef BSD @@ -27,12 +32,30 @@ extern long lrand48(); extern double drand48(); #define random() lrand48() +#define srandom(s) srand48((long)(s)) #define frandom() drand48() #endif #endif -#define urand(i) ((urperm[(i)&urmask]+frandom())/(urmask+1)) +extern unsigned short *urperm; +extern int urmask; -extern short *urperm; -extern int urmask; +#define urand(i) (urmask ? ((urperm[(i)&urmask]+frandom())/(urmask+1)) \ + : frandom()) + +extern int initurand(int size); + + /* 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_ */ +