php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #27919 [chm and php.net] bug on function.rand.html
Submitted: 2004-04-08 07:30 UTC Modified: 2004-04-08 11:07 UTC
From: kingoleg at mail dot ru Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.4 OS: windows
Private report: No CVE-ID: None
 [2004-04-08 07:30 UTC] kingoleg at mail dot ru
Description:
------------
I have found a bug on page http://www.php.net/manual/en/function.rand.php
[chm date: 2003-09-06]:
"On some platforms (such as Windows) RAND_MAX is only 32768. If you require a range larger than 32768, consider using mt_rand() instead."
It is not correct for example on WinXp.



Reproduce code:
---------------
<?php
echo rand(11111111111111,222222222222222222);
?>

Expected result:
----------------
first run:
127534874 (it is >larger than 32768)
second run
59053744 (it is >larger than 32768)


Actual result:
--------------
I think, that word "range" in this note is from early PHP version, when syntax was rand(start, rand). Now it rand(start, end).
I think, that words "such as Windows" must be replaced with "such as early versions of Windows".
Or, this note can be fully rewrited.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-08 11:07 UTC] irchtml@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

RAND_MAX is [about] 32768 on windows. 'echo getrandmax()' should give you that value.  That is the value used for the 'max' argument _if one is not specified_.  That's not to say a larger max cannot be used, RAND_MAX is the default.  As the manual says, "If called without the optional min, max arguments rand() returns a pseudo-random integer between 0 and RAND_MAX."

The note was a bit deceiving as it is entirely possible to specify a range much larger than 32768.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Nov 20 09:00:02 2025 UTC