Back to index

radiance  4R0+20100331
Defines | Functions | Variables
urand.c File Reference
#include "copyright.h"
#include <stdlib.h>
#include "standard.h"
#include "random.h"

Go to the source code of this file.

Defines

#define MAXORDER   (8*sizeof(unsigned short))

Functions

int initurand (int size)
int ilhash (int *d, int n)

Variables

static const char RCSid [] = "$Id: urand.c,v 2.10 2006/04/05 06:22:56 greg Exp $"
static unsigned short empty_tab = 0
unsigned short * urperm = &empty_tab
int urmask = 0

Define Documentation

#define MAXORDER   (8*sizeof(unsigned short))

Definition at line 17 of file urand.c.


Function Documentation

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:


Variable Documentation

unsigned short empty_tab = 0 [static]

Definition at line 19 of file urand.c.

const char RCSid[] = "$Id: urand.c,v 2.10 2006/04/05 06:22:56 greg Exp $" [static]

Definition at line 2 of file urand.c.

int urmask = 0

Definition at line 22 of file urand.c.

unsigned short* urperm = &empty_tab

Definition at line 21 of file urand.c.