[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

True Random (short c-source)

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

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

int   fGetRand (void);

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

   if(out==NULL) {
      printf("cant write to file random.bin\n");

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


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

   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.)