Path: cactus.org!milano!cs.utexas.edu!uunet!mcsun!sun4nl!alchemy!accucx!
+     nevries
From: nevries@accucx.cc.ruu.nl (Nico E de Vries)
Newsgroups: sci.crypt

Subject: IBM-PC random generator, graphical tester source
Message-ID: <2678@accucx.cc.ruu.nl>
Date: 23 Jun 92 12:24:06 GMT
Organization: Academic Computer Centre Utrecht
Lines: 78

First of all thanks to V Botchev for the great idea. While I spend ages
using all kind of pattern recognizers, higher order data compressors
etc it did not occur to me to use the best pattern recognizer I have,
my eyes!

This source can be used for testing me previously posted random generator.
It works on Hercules, EGA, VGA with the Borland BGI drivers. Both the
2D image like Botchev suggested and a histogram are generated.

**** WARNING **** I noticed some BCC optimization options have bugs
damaging operation of the random generator (shift left or XOR I don't
know). Disabling options or using Borland patches should solve the
problem.

The graphical viewer is nice to experiment with the 8 times repeat in
the random generator. For faster machines often a lower number is
sufficient. The lower the number the faster the random generator.

Nico E. de Vries
_ _
O O  USENET nevries@cc.ruu.nl  FIDO 2:281/708.1  COMPUSERVE "soon" (tm)
 o   This text reflects MY opinions, not that of my employer BITECH.      
\_/  This text is supplied 'AS IS', no waranties of any kind apply.      
     Don't waste your time on complaining about my hopeless typostyle.

"Unfortunately, the current generation of mail programs do not have checkers
 to see if the sender knows what he is talking about" (A.S. Tanenbaum)

===

#if 1 // TEST SOFTWARE #2, graphical investigation

// Can be used for testing BITECH random generator.
// At least hercules, EGA or VGA needed.
// Source uses Borland BGI.

#include 

static int ctr[256];

// update histogram
void upd (int i){
   ctr[i]++;
   line (i+266,255-ctr[i],i+266,255-ctr[i]);
}

void main (void){
   int i,j;
   unsigned long r;

   // INITIALIZE GRAPHICS
   int gdriver = DETECT, gmode, errorcode;
   initgraph(&gdriver, &gmode, "");
   errorcode = graphresult();
   if (errorcode != grOk){exit(1);}


   for (;;){
      // get 4 values in the range 0..255
      unsigned long r = Random();
      int x1 = r&255;
      int x2 = (r>>8)&255;
      int y1 = (r>>16)&255;
      int y2 = (r>>24)&255;

      // update histogram
      upd (x1); upd (x2); upd (y1); upd (y2);

      // update 2D image
      line (x1,y1,x1,y1);
      line (x2,y2,x2,y2);

      if (kbhit()) break;
   }

   closegraph();
}
#endif