• Advertisement
Sign in to follow this  

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

This topic is 4519 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[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]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement