www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/11/26/23:04:12

Message-ID: <000e01be198d$35d09da0$1cddefcf@chia>
From: "Chia" <chia AT top DOT net>
To: <djgpp AT delorie DOT com>
Subject: Re: Randomizing
Date: Thu, 26 Nov 1998 16:36:28 -0600
MIME-Version: 1.0
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 <stdlib.h>
    #include <time.h>

    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 <stdio.h>
  =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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML><HEAD>
<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type><!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 =
HTML//EN">
<META content=3D'"MSHTML 5.00.0910.1309"' name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3D"Times New Roman" size=3D2>It will always print the =
same thing=20
because the random number hasn't been seeded.</FONT></DIV>
<DIV><FONT face=3D"Times New Roman" size=3D2>To do that, use the=20
following:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Times New Roman" size=3D2>&nbsp;&nbsp;&nbsp; #include =

&lt;stdlib.h&gt;</FONT></DIV>
<DIV><FONT face=3D"Times New Roman" size=3D2>&nbsp;&nbsp;&nbsp; #include =

&lt;time.h&gt;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Times New Roman" size=3D2>&nbsp;&nbsp;&nbsp;=20
srand(time(0));</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Times New Roman" size=3D2>Then use the code you've=20
got.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Times New Roman" size=3D2>This will seed the random =
number=20
generator with the current time, producing a more random =
number.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Times New Roman" size=3D2>Hope it helps!</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>[ <A href=3D"mailto:chia AT top DOT net">chia AT top DOT net</A> ]<BR>[ <A=20
href=3D"mailto:jared AT underdark DOT net">jared AT underdark DOT net</A> ]<BR>[ <A=20
href=3D"mailto:ab031 AT thor DOT unomaha DOT edu">ab031 AT thor DOT unomaha DOT edu</A> =
]</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message -----=20
  <DIV style=3D"BACKGROUND: #e4e4e4; font-color: black"><B>From:</B> <A=20
  href=3D"mailto:lazer_hassing AT yahoo DOT com" =
title=3Dlazer_hassing AT yahoo DOT com>Lazer=20
  ---=A4---</A> </DIV>
  <DIV><B>Newsgroups:</B> comp.os.msdos.djgpp</DIV>
  <DIV><B>To:</B> <A href=3D"mailto:djgpp AT delorie DOT com"=20
  title=3Ddjgpp AT delorie DOT com>Djgpp mailing list</A> </DIV>
  <DIV><B>Sent:</B> Thursday, November 26, 1998 3:00 PM</DIV>
  <DIV><B>Subject:</B> Randomizing</DIV></DIV>
  <DIV><BR></DIV>
  <DIV><FONT size=3D2>Would anyone show me how to use =
rand()!!</FONT></DIV>
  <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2>I nede to get it to chose from 2 =
numbers</FONT></DIV>
  <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2>i've tryed this:</FONT></DIV>
  <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2>***********************************</FONT></DIV>
  <DIV><FONT size=3D2>#include &lt;stdio.h&gt;</FONT></DIV>
  <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2>int main()</FONT></DIV>
  <DIV><FONT size=3D2></FONT><FONT color=3D#000000 =
size=3D2>{</FONT></DIV>
  <DIV><FONT size=3D2>int my_number;</FONT></DIV>
  <DIV><FONT size=3D2>my_number=3Drand()%2;</FONT></DIV>
  <DIV><FONT size=3D2>printf(&quot;%d&quot;, my_number);</FONT></DIV>
  <DIV><FONT color=3D#000000 size=3D2>}</FONT></DIV>
  <DIV><FONT color=3D#000000=20
  size=3D2>***********************************</FONT></DIV>
  <DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT color=3D#000000 size=3D2>It always print 0 on the =
screen</FONT></DIV>
  <DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT color=3D#000000 size=3D2>Thanks!!</FONT></DIV>
  <DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT color=3D#000000 size=3D2>---&gt;=20
Lazer</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_000B_01BE195A.EA545920--

- Raw text -


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