From: Roger Carbol Newsgroups: comp.os.msdos.djgpp Subject: Re: random #'s Date: 29 Nov 1996 18:29:16 GMT Organization: iSTAR internet Incorporated Lines: 23 Message-ID: <57na1s$ame@nr1.calgary.istar.net> References: <329f264b DOT 60430893 AT nntp DOT southeast DOT net> Reply-To: rog AT col DOT ca NNTP-Posting-Host: 207.81.234.57 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Murray Stokely wrote: > > Whats the best way to generate a random number from 0 to 500? I > tried the x=random(500) (borland way) and i got some huge number. > After reading up on it I found out that random() always returns a # > between 0 and MAX_INT_SIZE how do i create a much smaller random #? The canonical answer has tended to be x=random(seed)%500 Where % returns the modulus (remainder) after dividing by 500. Seed is usually pulled from the system clock or keyboard timer or whatever. On the other hand, this is probably a non-runtime-speed-optimal way of generating random numbers...you could generate a look-up table during initialization, maybe... Roger Carbol .. rog AT col DOT ca .. order in chaos