Message-ID: <000e01be198d$35d09da0$1cddefcf@chia> From: "Chia" To: Subject: Re: Randomizing Date: Thu, 26 Nov 1998 16:36:28 -0600 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_000B_01BE195A.EA545920" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.0810.800 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.0810.800 Reply-To: djgpp AT delorie DOT com This is a multi-part message in MIME format. ------=_NextPart_000_000B_01BE195A.EA545920 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable It will always print the same thing because the random number hasn't = been seeded. To do that, use the following: #include #include srand(time(0)); Then use the code you've got. This will seed the random number generator with the current time, = producing a more random number. Hope it helps! [ chia AT top DOT net ] [ jared AT underdark DOT net ] [ ab031 AT thor DOT unomaha DOT edu ] ----- Original Message -----=20 From: Lazer ---=A4---=20 Newsgroups: comp.os.msdos.djgpp To: Djgpp mailing list=20 Sent: Thursday, November 26, 1998 3:00 PM Subject: Randomizing Would anyone show me how to use rand()!! =20 I nede to get it to chose from 2 numbers =20 i've tryed this: =20 *********************************** #include =20 int main() { int my_number; my_number=3Drand()%2; printf("%d", my_number); } *********************************** =20 It always print 0 on the screen =20 Thanks!! =20 ---> Lazer ------=_NextPart_000_000B_01BE195A.EA545920 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
It will always print the = same thing=20 because the random number hasn't been seeded.
To do that, use the=20 following:
 
    #include = <stdlib.h>
    #include = <time.h>
 
   =20 srand(time(0));
 
Then use the code you've=20 got.
 
This will seed the random = number=20 generator with the current time, producing a more random = number.
 
Hope it helps!
 
[ chia AT top DOT net ]
[ jared AT underdark DOT net ]
[ ab031 AT thor DOT unomaha DOT edu = ]
----- Original Message -----=20
From: Lazer=20 ---=A4---
Newsgroups: comp.os.msdos.djgpp
Sent: Thursday, November 26, 1998 3:00 PM
Subject: Randomizing

Would anyone show me how to use = rand()!!
 
I nede to get it to chose from 2 = numbers
 
i've tryed this:
 
***********************************
#include <stdio.h>
 
int main()
{
int my_number;
my_number=3Drand()%2;
printf("%d", my_number);
}
***********************************
 
It always print 0 on the = screen
 
Thanks!!
 
--->=20 Lazer
------=_NextPart_000_000B_01BE195A.EA545920--