Message-Id: <200005291856.VAA13282@mailgw1.netvision.net.il> Date: Mon, 29 May 2000 21:55:43 +0200 X-Mailer: Emacs 20.6 (via feedmail 8.1.emacs20_6 I) and Blat ver 1.8.5b From: "Eli Zaretskii" To: djgpp AT delorie DOT com In-reply-to: (message from Damian Yerrick on Mon, 29 May 2000 17:30:06 GMT) Subject: Re: Random numbers References: <392CB951 DOT 34B432E6 AT chemistry DOT uq DOT edu DOT au> Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > From: Damian Yerrick > Newsgroups: comp.os.msdos.djgpp > Date: Mon, 29 May 2000 17:30:06 GMT > > 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? The emulator is not required for the RNG, it is required for FP operations. The fragment from the FAQ uses a cast to double, to force FP computations: that's what triggers SIGNOFP. > Or can I do this to get rid of the unrandom low-order > bits? > nextPiece = (rand() >> 4) % 5; You are assuming that bits 4 to 6 are random enough. I don't think you can do that without testing.