Message-ID: <01BBDE40.57785E00@sky38.dataplusnet.com> From: Michael Matczynski To: "'DJGPP mailing list'" Subject: Re: random #'s Date: Fri, 29 Nov 1996 21:57:39 -0600 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit I wrote this program and it proves that it is an accurate random number generator. <<>> #include #include /* for random() */ #include /* for time() */ #include /* for tolower() */ int main( void ) { int r,x,y,number_one,number_two,number_three,number_four,number_five; number_one = number_two = number_three = number_four = number_five = 0; x=0; /* seed RNG with clock value - otherwise random() will always return the same sequence */ srandom( (int) time( 0 ) ); printf( "Type a 'q' to move on to the next example, or press Enter to continue." ); while ( tolower( getchar( ) ) != 'q' ) { r = random( ) % 501; /* 0 to 500 */ printf( "The random number is: %d", r ); } printf("Hold on, this may take a little while (10 seconds on my Pentium 100) . \n"); do{ y = random( ) % 501; if((y >= 0) && (y < 100)) number_one++; if((y >= 100) && (y < 200)) number_two++; if((y >= 200) && (y < 300)) number_three++; if((y >= 300) && (y < 400)) number_four++; if((y >= 400) && (y < 500)) number_five++; x++; } while(x<10000000); printf(" 0 to 100 = %d \n",number_one); printf("100 to 200 = %d \n",number_two); printf("200 to 300 = %d \n",number_three); printf("300 to 400 = %d \n",number_four); printf("400 to 500 = %d \n",number_five); return 0; } <<>>