php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #40408 rand: include a notice that "max" parameter must not exceed getrandmax()
Submitted: 2007-02-08 20:36 UTC Modified: 2007-03-23 18:40 UTC
From: burg1 at gmx dot net Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: burg1 at gmx dot net
New email:
PHP Version: OS:

 

 [2007-02-08 20:36 UTC] burg1 at gmx dot net
Description:
------------
I'm suggestion to revise this sentence in the docs:
"If you require a range larger than 32768, specifying min and max will allow you to create a range larger than RAND_MAX, or consider using mt_rand() instead."

1) As far as I can see, the max parameter cannot be larger than getrandmax(), otherwise rand() always returns 0. Please mention this limit! (I'm not sure if this behavior is platform-depended or due to PHP-internal integer handling, so I cannot suggest a reformulation.)

2) As far as I can see, this limit also applies to mt_rand(), so the last subsentence "or consider using mt_rand() instead" doesn't make sense to me.

3) Since mt_rand generates a "better random value", please include an explicit Note about this fact.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-23 17:20 UTC] vrana@php.net
1) max can be higher than getrandmax(). Random number however will have only granularity of getrandmax().

2) No.

3) mt_rand() is already linked from the page.

 [2007-03-23 18:40 UTC] burg1 at gmx dot net
3) Yes, but maybe you could state explicitly that mt_rand() "generates a better random value".
Currently, the first link ("If you require a range larger...") misses this point and the second link ("See also") is too unspecific.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Aug 06 23:00:03 2025 UTC