www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/15/20:19:09

Message-Id: <199801160123.RAA23681@m3.sprynet.com>
Reply-To: <darnold02 AT sprynet DOT com>
From: "Don Arnold" <darnold02 AT sprynet DOT com>
To: "Geoff J. Howard" <howard AT duke DOT usask DOT ca>, <djgpp AT delorie DOT com>
Subject: Re: rand() problem
Date: Thu, 15 Jan 1998 19:14:00 -0600
MIME-Version: 1.0

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019