From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: How to limit a random() with DJGPP ? Date: Wed, 25 Feb 1998 22:07:37 -0500 Organization: Two pounds of chaos and a pinch of salt. Lines: 27 Message-ID: <34F4DC79.6499@cs.com> References: <01bd41f9$d7ef7aa0$cd2f86c2 AT pieter> NNTP-Posting-Host: ppp204.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Pieter van Ginkel wrote: > > #define Random(x) (random() % x) > and then just use Random. This works quite well. The only thing with this is > that you can't get random numbers bigger that MAXINT. I think rand() does > this but you should find that out yourself. What's wrong with MAXINT? It is 2^32 in a 32-bit program. If you're really nuts about high-power integer numbers, write your own RNG that uses a long long seed instead of int. > If you want to have a random function that gives a floatingpoint result, > usae something like this. > > #define FPRandom() (random() / (double)MAXINT) This is not a really good solution because its granularity will still be limited to the range of MAXINT. For really good random floating point values, a custom RNG is almost mandatory. -- --------------------------------------------------------------------- | John M. Aldrich | "Sex should be friendly. Otherwise | | aka Fighteer I | stick to mechanical toys; it's more | | mailto:fighteer AT cs DOT com | sanitary." | | http://www.cs.com/fighteer | - Lazarus Long | ---------------------------------------------------------------------