www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/27/07:32:38

Message-ID: <368628DC.FAD5AABD@lycosmail.com>
Date: Sun, 27 Dec 1998 07:32:29 -0500
From: Adam Schrotenboer <ajschrotenboer AT lycosmail DOT com>
X-Mailer: Mozilla 4.5 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: getting a ranged random number, how?
References: <3685970D DOT 271BE4C6 AT market DOT forsale> <pWfh2.1536$fz5 DOT 121 AT tundra DOT ops DOT attcanada DOT net> <3685DB37 DOT 3EC8E298 AT earthlink DOT net>
Reply-To: djgpp AT delorie DOT com

You do have a point that it can be bad, but what if when you try to use RAND_MAX, your
compiler gives you a really hard time?? Don't remember exactly what happened when I
tried it, it was a while back. I was trying to seed a randgen that needs 3 seeds. The
easiest way was to seed the regular randgen, and then take the first 3 numbers. I
eventually had to use the mod method, because nothing else could be made to work.

Martin Ambuhl wrote:

> DeHackEd wrote:
> >
> > A common practice is to do this:
> >
> > int num = rand() % max;
> >
> > Num now contains a number between 0 and (max - 1). If max is 10, it holds from 0
> > to 9. Does this help?
>
> It shouldn't help.  If it is a common practice, then common practice is
> bad.  Get and read the comp.lang.c FAQ from
> ftp://rtfm.mit.edu/pub/usenet/
>
> --
> Martin Ambuhl (mambuhl AT earthlink DOT net)
> Note: mambuhl AT tiac DOT net will soon be inactive

- Raw text -


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