#40408 [Bgs]: rand: include a notice that "max" parameter must not exceed getrandmax()

From: Date: Fri, 23 Mar 2007 18:40:05 +0000
Subject: #40408 [Bgs]: rand: include a notice that "max" parameter must not exceed getrandmax()
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969375875@lists.php.net to get a copy of this message
ID: 40408 User updated by: burg1 at gmx dot net Reported By: burg1 at gmx dot net Status: Bogus Bug Type: Documentation problem PHP Version: Irrelevant New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2007-03-23 17:20:11] 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-02-08 20:36:46] 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. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=40408&edit=1

« previous php.doc (#969375875) next »