From: "Student, T.U.E." Newsgroups: comp.os.msdos.djgpp Subject: Re: Random Number? Date: Fri, 7 Jan 2000 18:07:46 +0100 Organization: Eindhoven University of Technology, The Netherlands Lines: 33 Message-ID: <8556h8$h32$1@news.tue.nl> References: <855200$31$1 AT hammer DOT msfc DOT nasa DOT gov> NNTP-Posting-Host: n125.dial.tue.nl X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Nick Haines wrote in message news:<855200$31$1 AT hammer DOT msfc DOT nasa DOT gov>... > How do you generate a random # in djgpp? (Yes I'm a newbie) Thanks for any > help you can give. > > There are two ways to do it: 1. With the function rand(), found in stdlib.h. You'll first have to type srand(time(0)) to seed the random number generator. Then you have to call rand(). rand() return a number between zero and RAND_MAX (defined in stdlib.h). To let rand() return a number between 0..N, simply type rand()%N+1, where the % stands for MODULO. This method is best for larger numbers. 2. With the function random(), found in stdlib.h. You'll first have to type srandom(time(0)), for the same reasons as mentioned above. Then you'll have to call random(). random() returns a number between zero and MAXINT. To let random() return a number between 0..N use the modulo method as mentioned above. Use this method to generate smaller numbers. Still questions? Mail me. Ton van den Heuvel mailto://A DOT W DOT v DOT d DOT Heuvel AT Student DOT tue DOT nl