From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: Random Numbers Date: Mon, 02 Feb 1998 19:03:06 -0500 Organization: Two pounds of chaos and a pinch of salt. Lines: 32 Message-ID: <34D65EBA.236C@cs.com> References: NNTP-Posting-Host: ppp229.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Tim Elliott wrote: > > How do I get a random number in DJGPP like say a random number between 1 to 100? Read the libc docs: "info libc alpha random"... "info libc alpha srandom". Remember that DJGPP != Borland; you must seed the random number generator yourself, and random() returns a value from 0 to MAXINT that you must clip to the desired range. Sample code: #include #include #include int main( void ) { int i; srandom( (int) time( NULL ) ); for ( i = 0; i < 100; i++ ) printf( "%3d ", random( ) % 100 + 1 ); printf( "\n" ); return 0; } -- --------------------------------------------------------------------- | John M. Aldrich | "Animals can be driven crazy by pla- | | aka Fighteer I | cing too many in too small a pen. | | mailto:fighteer AT cs DOT com | Homo sapiens is the only animal that | | http://www.cs.com/fighteer | voluntarily does this to himself." | ---------------------------------------------------------------------