|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8646 rand() or getrandmax() is broken
Submitted: 2001-01-10 20:52 UTC Modified: 2001-03-20 15:53 UTC
From: partek at hotmail dot com Assigned:
Status: Closed Package: Math related
PHP Version: 4.0.4 OS: Solaris 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: partek at hotmail dot com
New email:
PHP Version: OS:


 [2001-01-10 20:52 UTC] partek at hotmail dot com
I'm in the middle of porting a php-3.0.16 website to php-4.0.4, and have
run into a minor snafu. There seems to be a difference between what rand() can use, and what getrandmax() reports. The difference seems to lie in one
function using RAND_MAX and the other using PHP_RAND_MAX.

In php_rand.h the #if HAVE_LRAND48 is satisfied, therefore PHP_RAND_MAX gets set to 2147483647,  instead of the system default of
32767 set in /usr/include/stdlib.h. I notice in php-3.0.16 the PHP_RAND_MAX value of 2147483647 is the one that gets used across the board. Would it cause instability to substitute PHP_RAND_MAX for RAND_MAX on line 246 of ext/standard/rand.c?


When I do:

  $randnum = rand(1,99999);

It produces the following result:

<b>Warning</b>:  rand():  Invalid range:  1..99999 in <b>/WWW/</b> on line <b>537</b><br>

A call to getrandmax(); produces the result of 2147483647 

line 246 of ext/standard/rand.c uses RAND_MAX

 }else if ((*p_max)->value.lval-(*p_min)->value.lval > RA

line 346 of ext/standard/rand.c uses PHP_RAND_MAX

        return_value->value.lval = PHP_RAND_MAX;



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-20 15:53 UTC]
The proposed fix looks ok. Applied to CVS.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 14 01:01:27 2024 UTC