Message-ID: <379A42F1.AF23A6DF@vetec.com> Date: Sat, 24 Jul 1999 17:49:21 -0500 From: Andy Goth X-Mailer: Mozilla 4.5 [en] (Win95; I) X-Accept-Language: en MIME-Version: 1.0 To: djgpp AT delorie DOT com Subject: Re: -- Random question -- References: <7nd0vu$igt$1 AT zingo DOT tninet DOT se> <7nd9so$a96 AT dfw-ixnews3 DOT ix DOT netcom DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com > You can use the remainder operator like this: > > number = (rand() % 101) + 1; The rand() % 101 part will return a number from 0 to 100, so if you add one to that you get 1 to 101. Try (rand() % 100) + 1 instead (1 to 100). > This will generate a number from 1 to 100. You can also substitute rand() > with random() which generates numbers that are more random, but random() > isn't as portable. Don't forget to seed it at the start of your program like > this: > > srand(time(0)); /* for rand() */ > srandom(time(0)); /* for random() */