I'm trying to determine if RAND_MAX can fit inside an unsigned int variable. After looking through the C99 standard, I have only found that RAND_MAX is guaranteed to have a value of at least 32767. While I know that RAND_MAX expands to int value, I'm not sure if it's a long int. Right now I'm working with unsigned long int variables, but I would like to simplify my source code to use unsigned int variables.
To summarize, is this assumption statement true for the C99 standard:
RAND_MAX <= UINT_MAX <= ULONG_MAX
Also, is RAND_MAX is explicitly less than (i.e. not equal to) UINT_MAX or ULONG_MAX. I realize that the value of RAND_MAX is often a Mersenne prime, but I'm not sure if this is a standard.
RAND_MAX is the maximum value that can be returned by rand(). Since rand() is defined as returning int, RAND_MAX will be no more than INT_MAX, and therefore also no more than UINT_MAX.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With