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

From: Date: Fri, 23 Mar 2007 17:20:11 +0000
Subject: #40408 [Opn->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-969375867@lists.php.net to get a copy of this message
ID: 40408 Updated by: vrana@php.net Reported By: burg1 at gmx dot net -Status: Open +Status: Bogus Bug Type: Documentation problem PHP Version: Irrelevant New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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 (#969375867) next »