Mail Archives: djgpp/1998/01/22/23:15:33
Mirek Prywata wrote:
>
> George Foot wrote:
> >
> > : That's true, I was wrong. I simply meant
> > : int random(int) and not int random (void)
> >
> > ... but even so, random does not take an integer. I don't have djgpp
> > here to check, but the prototype should be `int random (void);'.
>
> if you want to have random numbers, but not as big as RAND_MAX (or
> MAX_RAND - I don't remember) then you can easily make random() that
> returns numbers from <0,MY_RAND_MAX>. That's random(int) i meant.
Wrong again. Unless you are using C++, you can't name your own function
the same as a library function that it calls. The following code is
logically and syntactically incorrect:
#include <stdlib.h>
int random( int x )
{
return random() % x;
}
That code will not compile, unless you are using a truly dumb compiler,
or you're using C++'s overload features, in which case this discussion
properly applies to C++, not C. Anyway, overloading a library function
not designed specifically for C++ is a Bad Thing, IMHO.
If your only concern is that Borland's random() takes an integer range,
and DJGPP's doesn't, then you can conditionally compile your code to use
random(x) on Borland, and random() % x on DJGPP.
> IMHO there's no point in using different generator from rand(). If you
> want to have better generator you must write it on your own, in order to
> know, how it works.
The DJGPP random() function is non-ANSI, but it uses a much improved
algorithm over the ANSI-standard rand() library function. If you write
code mainly for DJGPP, there's no reason not to use random(). If you
write code that must be portable, then it's best either to use #ifdef's
to conditionally use whatever RNG features exist for a given compiler,
or to write your own RNG from scratch (because their quality varies
highly from compiler to compiler).
--
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I | mailto:fighteer AT cs DOT com |
| Plan: To find ANYONE willing to | http://www.cs.com/fighteer |
| play Descent 2 on DWANGO! | Tagline: <this space for rent> |
---------------------------------------------------------------------
- Raw text -