From: George Foot Newsgroups: comp.os.msdos.djgpp Subject: Re: rand() or random() Date: 5 Nov 1997 00:56:20 GMT Organization: Oxford University, England Lines: 28 Message-ID: <63og7k$8jr$4@news.ox.ac.uk> References: <63mh1a$9r4$1 AT postern DOT mbnet DOT mb DOT ca> <#Lau#NX68GA DOT 291 AT upnetnews02 DOT moswest DOT msn DOT net> NNTP-Posting-Host: sable.ox.ac.uk To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Mark Phillips wrote: ] Just for the heck of it, say I want to get a random number from 0 to ] 19. rand() and random() appear to return numbers from 0 to 2^31. I ] could always do rand() * 20 / 2^31 but there must be a better way. note: 2^31 does not mean 2 raised to the 31st power; it means 2 exclusive-ORed with 31, which is 29. Ryan Blazecka wrote: > How about rand() % 19? :) You meant `rand() % 20'. Carolyn Kelly-Pajot wrote: : if you want a number from 0-19, type : int random_number = rand() % 20; : This returns the REMAINDER from division by 20, which will be between 1 and 19 : inclusive. ... and you meant `between 0 and 19 inclusive'. :) -- Regards, george DOT foot AT merton DOT oxford DOT ac DOT uk