www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/05/29/13:30:52

From: Damian Yerrick <Bullcr_pd_yerrick AT hotmail DOT comRemoveBullcr_p>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Random numbers
Organization: Pin Eight Software http://pineight.8m.com/
Message-ID: <cs95jscumbafalh5jj0f8l6dm1u0uiq5o5@4ax.com>
References: <392CB951 DOT 34B432E6 AT chemistry DOT uq DOT edu DOT au> <Pine DOT SUN DOT 3 DOT 91 DOT 1000525084705 DOT 21360M-100000 AT is>
X-Newsreader: Forte Agent 1.7/32.534
MIME-Version: 1.0
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
<eliz AT is DOT elta DOT co DOT il> 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 <stdlib.h>

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019