Re: $max > getmaxrand() for rand() call

From: Date: Mon, 13 Apr 2015 20:06:56 +0000
Subject: Re: $max > getmaxrand() for rand() call
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-85790@lists.php.net to get a copy of this message
Rowan Collins wrote: > To be fair, that's not actually mutually exclusive with Leszek's > suggestions - we still need to either document, or warn, that rand() has > this limitation. The manual does actually mention using mt_rand(), but > also suggests setting $max higher than getrandmax(), which is probably > bad advice: > >> If you require a range larger than 32767, specifying |min| and |max| > will allow you to create a range larger than this, or consider using > mt_rand() <http://php.net/manual/en/function.mt-rand.php> > instead. It seems to be noteworthy that the mt_rand man page contains a respective warning[1], and the mt_getrandmax man page explains the issue in the "Return Values" section[2]. I think it would be reasonable to document rand/getrandmax alike in this regard. [1] <http://php.net/manual/en/function.mt-rand.php#refsect1-function.mt-rand-notes> [2] <http://php.net/manual/en/function.mt-getrandmax.php#refsect1-function.mt-getrandmax-returnvalues> -- Christoph M. Becker

« previous php.internals (#85790) next »