Back to index

radiance  4R0+20100331
Defines | Functions | Variables
random.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define random()   lrand48()
#define srandom(s)   srand48((long)(s))
#define frandom()   drand48()
#define urand(i)

Functions

long lrand48 ()
double drand48 ()
int initurand (int size)
int ilhash (int *d, int n)
int urind (int s, int i)
void multisamp (double t[], int n, double r)

Variables

unsigned short * urperm
int urmask

Define Documentation

#define frandom ( )    drand48()

Definition at line 36 of file random.h.

#define random ( )    lrand48()

Definition at line 34 of file random.h.

#define srandom (   s)    srand48((long)(s))

Definition at line 35 of file random.h.

#define urand (   i)
Value:
(urmask ? (urperm[(i)&urmask]+frandom())/(urmask+1) \
                            : frandom())

Definition at line 44 of file random.h.


Function Documentation

double drand48 ( )
int ilhash ( int *  d,
int  n 
)

Definition at line 63 of file urand.c.

{
       static int  tab[8] = {103699,96289,73771,65203,81119,87037,92051,98899};
       register int  hval;

       hval = 0;
       while (n-- > 0)
              hval ^= *d++ * tab[n&7];
       return(hval & 0x7fffffff);
}

Here is the caller graph for this function:

int initurand ( int  size)

Definition at line 25 of file urand.c.

{
       int  order, n;
       register int  i, offset;

       if ((urperm != NULL) & (urperm != &empty_tab))
              free((void *)urperm);
       if (--size <= 0) {
              empty_tab = 0;
              urperm = &empty_tab;
              urmask = 0;
              return(0);
       }
       for (i = 1; (size >>= 1); i++)
              if (i == MAXORDER)
                     break;
       order = i;
       urmask = (1<<order) - 1;
       urperm = (unsigned short *)malloc((urmask+1)*sizeof(unsigned short));
       if (urperm == NULL) {
              eputs("out of memory in initurand\n");
              quit(1);
       }
       urperm[0] = 0;
       for (n = 1, offset = 1; n <= order; n++, offset <<= 1)
              for (i = offset; i--; ) {
                     urperm[i+offset] = urperm[i] <<= 1;
                     if (random() & 0x4000)
                            urperm[i]++;
                     else
                            urperm[i+offset]++;
              }
       return(urmask+1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

long lrand48 ( )
void multisamp ( double  t[],
int  n,
double  r 
)
int urind ( int  s,
int  i 
)

Definition at line 42 of file urind.c.

{
       register int  ss, k;
       int  left;

       ss = s*1103515245 + 12345;
       left = 0;
       for (k = i/NBITS; k--; ) {
              left += bitcount(ss);
              ss = ss*1103515245 + 12345;
       }
       for (k = i&(NBITS-1); k--; ss >>= 1)
              left += ss & 1;
       if (ss & 1)
              return(s-left-1);
       return(s-left+i);
}

Variable Documentation

int urmask

Definition at line 22 of file urand.c.

unsigned short* urperm

Definition at line 21 of file urand.c.