/***************** RANDOMS.C ******************/
#include <graphics.h>
#include <string.h>
#include "randefs.h"
#include "probab.h"
#include "datacomp.h"
#include "displays.h"
#include <stdlib.h>

/**************** Label Arrays ****************/
static char *coin[] =
{"  HEAD","  TAIL", "ONE COIN:"};
static char *loadedcoin[] =
{"  HEAD","  TAIL", "LOADED COIN:"};
static char *twocoins[] =
{"  H,H","HT/TH","  T,T", "TWO COINS:"};
static char *onedie[] =
{" 1"," 2"," 3"," 4"," 5"," 6", "ONE DIE:"};
static char *twodice[] =
{"2","3","4","5","6","7","8","9","10","11","12",
 "TWO DICE:"};
static char *loadeddice[] =
{"2","3","4","5","6","7","8","9","10","11","12",
 "LOADED DICE:"};
static char *fourdice[] =
{"4","5","6","7","8", "9","10","11","12","13","14",
 "15","16","17","18","19","20","21","22","23","24",
 "FOUR DICE:"};
static char *normal[] =
{"-3","","","","-2","","","","-1","","","",
 " 0","","",""," 1","","",""," 2","","",""," 3",
 "NORMAL DISTRIBUTION:"};
static char *uniform_circular[] =
{"0",  "","","","","","90", "","","","","",
 "180","","","","","","270","","","","","",
 "UNIFORM CIRCULAR:"};

static RAND tbl[] = {
 {2, 1, Dummy,   0, 2, 0, 1.0, coin      },
 {2, 1, LoadZero,0, 2, 0, 1.0, loadedcoin},
 {2, 2, Dummy,   0, 3, 0, 1.0, twocoins  },
 {6, 1, Dummy,   0, 6, 0, 1.0, onedie    },
 {6, 2, Dummy,   0, 11,0, 1.0, twodice   },
 {6, 2, LoadZero,0, 11,0, 1.0, loadeddice},
 {6, 4, Dummy,   0, 21,0, 1.0, fourdice  },
 {25,1, Normal,  0, 25,0, 0.25,normal    },
 {24,1, Dummy,   0, 24,0, 1.0, uniform_circular}
};

static int filtr_wts[][MAXWTLEN] = {
  /** Running Average **/
  {11, 11, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
  /** Low-Pass RC, ratio = 1.2 **/
  {11,322,10,12,14,17,21,25,30,36,43,52,62 },
  /** Differentiator  **/
  {13, 12,-1,-1,-1,-1,-1,-1, 0, 1, 1, 1, 1, 1, 1 }
};

void main(void)
{
  int   k, kmax = DIM(tbl), gmode, errorcode,
        gdriver = DETECT;  /* request autodetect */
  RAND  xampl;             /* an example         */

  initgraph(&gdriver, &gmode, "");
  setviewport(OFFX, OFFY-FS, OFFX+SPAN, OFFY-1,0);

  for (k = 0; k < kmax; k++)
  {  memcpy((void *)&xampl,(void *)&tbl[k],sizeof(RAND));
     if (MakeHistogram(&xampl) )
        break;
     if (RandWalk(&xampl) )
        break;
     MakeScopeSignals(&xampl, filtr_wts);
     if (ESC == getch() )   /* User's chance to exit */
        break;
  }
  closegraph();
}
