www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/08/02:53:12

From: "Student, T.U.E." <YourName AT student DOT tue DOT nl>
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 <nick DOT haines AT msfc DOT nasa DOT gov> 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


- Raw text -


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