delorie.com/archives/browse.cgi | search |
Date: | Fri, 16 Jul 1999 13:16:00 -0400 (CST) |
From: | Mitchell Cifuentes <mcifuent AT belen DOT electa DOT uta DOT cl> |
To: | djgpp AT delorie DOT com |
Subject: | Re: ---Random question--- |
In-Reply-To: | <7mnf45$pqb$2@cubacola.tninet.se> |
Message-ID: | <Pine.OSF.3.96.990716131224.19404D-100000@belen.electa.uta.cl> |
MIME-Version: | 1.0 |
X-MIME-Autoconverted: | from QUOTED-PRINTABLE to 8bit by delorie.com id NAA02329 |
Reply-To: | djgpp AT delorie DOT com |
X-Mailing-List: | djgpp AT delorie DOT com |
X-Unsubscribes-To: | listserv AT delorie DOT com |
On Fri, 16 Jul 1999, Börje Granberg wrote: > I know there are commands like rand() and random() but how do I get a random > number between 1 and 100? > > In BASIC it is easy because there you get a random (float) number between 0 > and 1 that you can multiplicate with 100 and add 1, but I dont see that > opportunity in C++ or have my eyes missed that part? > > > -- > /Börje > > > > > > Try this : rand() % 101 the above gives you the rest of divisio of rand()/101 (a number in the range 0-100
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |