From ted@cis.ufl.edu Tue Jan 25 13:27:23 1994
Received: from squall.cis.ufl.edu by SHASHA.CS.NYU.EDU (5.61/1.34)
	id AA26804; Tue, 25 Jan 94 13:27:19 -0500
From: ted@cis.ufl.edu
Received:  from localhost  by squall.cis.ufl.edu (8.6.4/4.11)
	id NAA13237; Tue, 25 Jan 1994 13:27:18 -0500
Date: Tue, 25 Jan 1994 13:27:18 -0500
Message-Id: <199401251827.NAA13237@squall.cis.ufl.edu>
To: doshi@summit.novell.com, shasha@SHASHA.CS.NYU.EDU
Status: R

/*	Code from Paul Fishwick's SIMPACK, Modified by Ted Johnson
*/
/* Declarations for random distribution sampling */

#define then

#define A 16807L           /* multiplier (7**5) for 'ranf' */
#define M 2147483647L      /* modulus (2**31-1) for 'ranf' */

static long In[16]= {0L,   /* seeds for streams 1 thru 15  */
  1973272912L,  747177549L,   20464843L,  640830765L, 1098742207L,
    78126602L,   84743774L,  831312807L,  124667236L, 1172177002L,
  1124933064L, 1223960546L, 1878892440L, 1449793615L,  553303732L};

static int strm=1;         /* index of current stream */
static int normalizer;



double log();

/* These random number generator routines were written by
   M.H. MacDougall, "Simulating Computer Systems", MIT Press, 1987.
*/


/*-------------  UNIFORM [0, 1] RANDOM NUMBER GENERATOR  -------------*/
/*                                                                    */
/* This implementation is for Motorola 680x0 CPUs using C compilers   */
/* with 16-bit short integers and 32-bit long integers.               */
/*                                                                    */
/*--------------------------------------------------------------------*/
float ranf()
  {
  long sample;
  double dsamp,dnorm,ratio;
  float converted;
	sample=random();
	dsamp=(double)sample;
	dnorm=(double)normalizer;
	ratio=dsamp/dnorm;
        converted=(float)ratio;
    return(converted);
  }

/*--------------------  SELECT GENERATOR STREAM  ---------------------*/
stream(n)
  int n;
    { 
    int pwr,i;

        normalizer=0;pwr=1;
        for(i=0;i<31;i++)
        {
                normalizer+=pwr;
                pwr*=2;
        }

      srandom(n);

    }

/*--------------------------  SET/GET SEED  --------------------------*/
long seed(Ik,n)
  long Ik; int n;
    { /* set seed of stream n for Ik>0, return current seed for Ik=0  */
      /* if ((n<1)||(n>15)) then error(0,"seed Argument Error"); */
      if (Ik>0L) then  In[n]=Ik;
      return(In[n]);
    }

/*------------  UNIFORM [a, b] RANDOM VARIATE GENERATOR  -------------*/
float uniform(a,b)
  float a,b;
    { /* 'uniform' returns a psuedo-random variate from a uniform     */
      /* distribution with lower bound a and upper bound b.           */
      /* if (a>b) then error(0,"uniform Argument Error: a > b"); */
float t;
      t=ranf();
      return(a+(b-a)*t);
    }

/*--------------------  RANDOM INTEGER GENERATOR  --------------------*/
r_random(i,n)
  int i,n;
    { /* 'random' returns an integer equiprobably selected from the   */
      /* set of integers i, i+1, i+2, . . , n.                        */
      /* if (i>n) then error(0,"random Argument Error: i > n"); */
      n-=i; n=(n+1.0)*ranf();
      return(i+n);
    }

/*--------------  EXPONENTIAL RANDOM VARIATE GENERATOR  --------------*/
float expntl(x)
  float x;
    { /* 'expntl' returns a psuedo-random variate from a negative     */
      /* exponential distribution with mean x.                        */
float t1,t2;
      t1=ranf();
      t2=(float)log(t1);
      return(-x*t2);
    }

/*----------------  ERLANG RANDOM VARIATE GENERATOR  -----------------*/
float erlang(x,s)
  float x,s;
    { /* 'erlang' returns a psuedo-random variate from an erlang      */
      /* distribution with mean x and standard deviation s.           */
      int i,k; float z;
      /* if (s>x) then error(0,"erlang Argument Error: s > x"); */
      z=x/s; k=(int)z*z;
      z=1.0; for (i=0; i<k; i++) z *= ranf();
      return(-(x/k)*(float)log(z));
    }

/*-----------  HYPEREXPONENTIAL RANDOM VARIATE GENERATION  -----------*/
float hyperx(x,s)
  float x,s;
{}

/*-----------  TRIANGULAR RANDOM VARIATE GENERATION  -----------*/
float triang(a,c,b)
float a,c,b;
{
 /* triangular distribution with left and right being [a,b] and the
    mode being at point c */
}

/*-----------------  NORMAL RANDOM VARIATE GENERATOR  ----------------*/
float normal(x,s)
  float x,s;
    { /* 'normal' returns a psuedo-random variate from a normal dis-  */
      /* tribution with mean x and standard deviation s.              */
  }



