Jump to content
  • Advertisement
Sign in to follow this  
Wan

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

This topic is 4786 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!