1995-11-09 - True Random (short c-source)

Header Data

From: Frank Andrew Stevenson <frank@funcom.no>
To: cypherpunks@toad.com
Message Hash: d9783f3820ceb5f6bc2dcc0e4ba224ddb9a10e69f91bc1eb4b703108145b0cec
Message ID: <Pine.SGI.3.91.951108165325.25592A-100000@odin>
Reply To: N/A
UTC Datetime: 1995-11-09 01:14:16 UTC
Raw Date: Thu, 9 Nov 1995 09:14:16 +0800

Raw message

From: Frank Andrew Stevenson <frank@funcom.no>
Date: Thu, 9 Nov 1995 09:14:16 +0800
To: cypherpunks@toad.com
Subject: True Random (short c-source)
Message-ID: <Pine.SGI.3.91.951108165325.25592A-100000@odin>
MIME-Version: 1.0
Content-Type: text/plain


I have written a short random number generator which appears to produce
reasonable random numbers even in DOS, at the heart of the code is the
short function fGetRand, the amount of entropy derived from this
function varies from >1 to >>6 depending on system load, I haven't
made any effort to whiten it at all. I am not making any claims about
its usefulness. I am only trying to demonstrate the ease at which
good random number may be obtained. Any comments and analysis will be
mostly welcome, the source is hereby placed in the public domain:

I have used WATCOM10 to compile and test under DOS/WIN95, where
clock is running at 18hz. I have also tested on IRIX with impressive
results.

--- START ----
#include <time.h>
#include <stdio.h>

int   fGetRand (void);

main (void) {
   long vCount;
   FILE *out;
   int byte;
   int tick;

   out=fopen("random.bin","wb");
   if(out==NULL) {
      printf("cant write to file random.bin\n");
      exit(1);
   }

   for(vCount=1;vCount<=512;vCount++) {
      tick=fGetRand()&0x01;
      byte=byte+byte+tick;
      if((vCount & 0x7)==0) fputc((char)byte,out);
      fputc((char)tick,out);
   }

   fclose(out);
}


int   fGetRand (void) {
   int count;
   clock_t tick;

   tick=clock();
   while(tick==clock()) count++;

   return (count);
}
----- END -----

PGP encrypted mail preferred, finger for key.
The above views are ONLY endorsed by BoggleMind Inc. (not to be confused
with MindBoggle Ltd.)







Thread