Reputation: 55
Why is it not a const
? I think this is not a clear C++ way.
Perhaps there is a more C++ way to generate random numbers, is there?
Upvotes: 0
Views: 738
Reputation: 490218
It's a macro because it comes from C where it's been a macro for a long time.
Upvotes: 1
Reputation: 355089
RAND_MAX
comes from the C standard library, where it is defined as a macro.
In C, macros are the way manifest constants are defined. A const
object isn't actually a constant in C (this means a const
object cannot be used in constant expressions).
Upvotes: 11
Reputation: 22814
If you're looking for a "more C++-way", you could use boost::random
.
Anyway, RAND_MAX
is a macro, because it comes from "legacy C" rand()
function, where using preprocessor symbols for declaring constants was a de-facto standard.
Upvotes: 6