From: Jerzy DOT Witkowski AT ii DOT uni DOT wroc DOT pl (Jerzy Witkowski) Newsgroups: comp.os.msdos.djgpp Subject: Re: a randomize function for DJGPP? Date: 10 Mar 1997 09:44:59 +0100 Organization: University of Wroclaw Lines: 24 Sender: jwi AT swiatowit DOT ii DOT uni DOT wroc DOT pl Message-ID: References: <5flbpp$m74 AT nr1 DOT ottawa DOT istar DOT net> <331FC0D1 DOT 1A26 AT cs DOT com> <5fps67$pc3 AT news DOT ox DOT ac DOT uk> NNTP-Posting-Host: swiatowit.ii.uni.wroc.pl In-reply-to: cigna@helios.phy.OhioU.Edu's message of Sun, 9 Mar 1997 21:08:12 GMT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In article cigna AT helios DOT phy DOT OhioU DOT Edu (Dave Cigna) writes: > >: The best way to get get random numbers uniformly distributed from > >: 0 to X-1 is to use: > > > >: n = ((double)random() / RAND_MAX) * X; RAND_MAX should be used with rand() function. MAXINT should be used with random() function. To get integer random number from 0 to X-1 you could use (random()%X). To get real random number from [0,1) you could use ((double)random()/((double)MAXINT+1.0)) (multiply it by X in your case). Hope this helps, -- Jerzy Witkowski o o University of Wroclaw, Institute of Computer Science /| | |/| Przesmyckiego 20, PL-51151 Wroclaw |/| | | room: 11, phone: 0048 71 3247360 /| |/^\| | phone/fax office secretary: 0048 71 3251271 <__|