Why does rand() return (max) 32767 when RAND_MAX is defined as 0x7fffffff?
Why does rand() return (max) 32767 when RAND_MAX is defined as 0x7fffffff?
Using the 15.02 toolchain for RX100 series and stdlib.h, we found that rand() always returns a value < 32768 (implying an int16_t) even though __RAND_MAX is defined in config.h as 0x7fffffff (int32_t).
Is this intended behavior, a bug, or does it require setting a macro value in the project?
Hello,
We appreciate your patience while we investigated the issue.
We were able to reproduce the problem on our end, as follows:
- when using optlib, the problem is reproducible easily:
- please search the toolchain installation folder (versions below 16.01), specifically in file “\rx-elf\rx-elf\rx-elf\optlibinc\stdlib.h”, and you will find the definition of RAND_MAX is:
#define RAND_MAX 32767
which is, of course, 0x7FFF
- please search the toolchain installation folder (versions below 16.01), specifically in file “\rx-elf\rx-elf\rx-elf\optlibinc\stdlib.h”, and you will find the definition of RAND_MAX is:
- when using newlib, the value of RAND_MAX is correct, so the issue does not happen at all;
We hope this clarifies the situation. Please let us know if you have any other questions or if you need any additional help from our end.
—
Thank you,
The GNU Tools Support Team
×
Hello,
Thank you for your feedback!
This is a confirmation message to let you know that we have received your request and that we are looking into it as soon as possible.
We will be getting back to you soon with our findings.
—
Thank you,
Adrian
The GNU Tools Support Team