#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include </mit/cds/languages/elk/src/scheme.h>
#define HANDLE_PMF_CHAR_PER_ENTRY 10
#define HANDLE_PMF_INITIAL_CHAR 32
#define MAXLENGTH 1000
#define LISTLENGTH 30

int T_Queue;

Object handle_queue_list (vect, list)
Object vect, list;
{
int curlength1, curtrials, listlength;
float birthprob, deathprob, varimult;

 /* internal declarations */
 float birth1prob, birth2prob;
 int i = 0;
 int true = 0;
 int totbirth1 = 0; 
 int totdeath1 = 0;
 int totbirth2 = 0;
 int totdeath2 = 0;
 long int totlength1 = 0;
 int tottrials = 0;
 int strspc = 200;
 int totbalk1 = 0;
 int servsomeone = 0; /* 0 = yes, 1 = no */
 int servtype = 0;   /* 1 = type A, 2 = type B  (see Jeff Turcotte's '91    */ 
 float floatmax = 0.0;                       /*      bachelor's thesis      */
 float trial, typeserv;
 long foo, bar;
 Object head, tail;
  
floatmax = 2^31 -1;
i = 0;
 head = PAIR(list)->car;
curtrials = FIXNUM(head);
list = PAIR(list)->cdr;

 head = PAIR(list)->car;
curlength1 = FIXNUM(head);
list = PAIR(list)->cdr;

 head = PAIR(list)->car;
 birth1prob = FLONUM(head)->val;
list = PAIR(list)->cdr;

 head = PAIR(list)->car;
 deathprob = 1 - FLONUM(head)->val;

 bar = (65536 * 16384 + (65536 * 16384 - 1));

while (i < curtrials)
  {
    i++;

    trial = (float) random() / bar;
   if ( (trial < birth1prob) && (curlength1 == MAXLENGTH))
      {
       totbalk1++;
      }      
       else if (trial < birth1prob)
	 {
	   totbirth1++;
	   curlength1++;
	 } else
           {
             if ( (trial > deathprob) && (curlength1 > 0))
               {
                totdeath1++;
	        curlength1--;
               }
           }
   if (curlength1 <= LISTLENGTH) VECTOR(vect)->data[curlength1]++;
   totlength1 = totlength1 + curlength1;
 }

return Make_Fixnum(curlength1);

}
init_queue()
{
Define_Primitive (handle_queue_list, "queue_list", 2, 2, EVAL);
}
