Mail Archives: djgpp/1998/12/27/07:32:38
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 -