Sign in to follow this  

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this