[web] PHP defines RAND_MAX as 0 ?! [solved]

Started by
0 comments, last by Wan 18 years, 6 months ago
[solved] I'm using rand/mt_rand to generate some random numbers. In order to get a floating point value between 0.0F and 1.0F I divide it by the constant RAND_MAX (the return value's upper bound for the rand function). Exactly as you would do in C/C++. So far so good it seemed, yet it resulted in a lot of division by zero errors. It turned out that RAND_MAX is zero (using PHP5 on WinXP/IIS)! Of course I could work around this issue by doing something like rand(0, LARGE_NUMBER) / LARGE_NUMBER, but I would potentially lose precision and I really like to know what the hell is going on. Google didn't turn up any clues. Anyone else encountered this or knows a proper solution? [Edited by - WanMaster on October 6, 2005 6:57:19 AM]
Advertisement
Solved. Apparently one can find its value by using mt_getrandmax().

This topic is closed to new replies.

Advertisement