Mail Archives: djgpp/1998/01/15/20:19:09
you'll need to seed the rng with a call to srand() before you use it.
----------
> From: Geoff J. Howard <howard AT duke DOT usask DOT ca>
> To: djgpp AT delorie DOT com
> Subject: rand() problem
> Date: Thursday, January 15, 1998 13:02 PM
>
> Hello All,
>
> I am just new to the djgpp world of C computing and I tried out a
> simple random number program and kept getting the same "random" number
> generated all the time, which is either 0 or no number. Is this a known
> problem? I have included the code below. I am thinking that it could be
as
> a result of my computer not having enough RAM, what is the minimum amount
> I should have to run djgpp properly. Thanks all
>
> Geoff
>
> #include <stdio.h>
> #include <stdlib.h>
>
> main ()
> {
> int i;
>
> for (i=1; i<= 20; i++) {
> printf("%10d", 1 + (rand() % 6));
>
> if (i % 5 == 0)
> printf("\n");
> }
>
> return 0;
> }
- Raw text -