From: Damian Yerrick Newsgroups: comp.os.msdos.djgpp Subject: Re: Random numbers Organization: Pin Eight Software http://pineight.8m.com/ Message-ID: References: <392CB951 DOT 34B432E6 AT chemistry DOT uq DOT edu DOT au> X-Newsreader: Forte Agent 1.7/32.534 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 32 X-Trace: /bQNubpGGb+l78f6/rVMxyGZuKGDKW2asFyk1qWjP/uYd6hoaDVX6mzmCqiHhRWKxyLsRyCT2Ri/!H6XbFLW5FdQWtVcrvgwhpD8XgyLVgDGuUFtS3QLbCoS7ADrQR/e6HKaTfXZAbZjjMRE+3kFuCahh!a44= X-Complaints-To: abuse AT gte DOT net X-Abuse-Info: Please be sure to forward a copy of ALL headers X-Abuse-Info: Otherwise we will be unable to process your complaint properly NNTP-Posting-Date: Mon, 29 May 2000 17:30:06 GMT Distribution: world Date: Mon, 29 May 2000 17:30:06 GMT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Thu, 25 May 2000 08:49:55 +0300 (IDT), Eli Zaretskii wrote: >The recommended way to generate random numbers from a smaller range is >described in section 22.23 of the DJGPP FAQ list, which see. The FAQ entry describes the "rescaling" technique: #include int random_number = low + (double)rand () * (high - low + 1) / RAND_MAX; When I do this on my target platform (386 PC), the cast to double produces SIGNOFPE. Including emu387.dxe and emu387.bat (a script to insert the required environment variables) fixed it. @ECHO OFF SET 387=N SET EMU387=C:\PINEIGHT\EMU387.DXE Does this mean I have to bundle emu387.dxe with all programs that use random numbers? Or can I do this to get rid of the unrandom low-order bits? nextPiece = (rand() >> 4) % 5; -- Damian Yerrick "I refuse to listen to those who refuse to listen to reason." See the whole sig: http://www.rose-hulman.edu/~yerricde/sig.html This is McAfee VirusScan. Add these two lines to your signature to prevent the spread of signature viruses. http://www.mcafee.com/