Mail Archives: djgpp/1998/02/02/19:18:42
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 <stdio.h>
#include <stdlib.h>
#include <time.h>
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." |
---------------------------------------------------------------------
- Raw text -