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_MAXis the maximum value that can be returned byrand(). Sincerand()is defined as returningint,RAND_MAXwill be no more thanINT_MAX, and therefore also no more thanUINT_MAX.