Re: BC break with rand() where min > max
| From: | Tom Worster | Date: | Wed, 10 Aug 2016 13:18:56 +0000 |
| Subject: | Re: BC break with rand() where min > max | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-95003@lists.php.net to get a copy of this message | ||
On 8/8/16 5:36 PM, Leigh wrote:
Hi all, There has been an unforeseen break with rand() when the minimum value is greater than the maximum. Prior to 7.1 rand() would happily accept backwards parameters and return a value, however in the 7.1 branch it now emits a warning and returns false. I've preemptively committed a fix to allow min > max and return a value as in previous versions, but have kept the warning. Looking for some feedback/opinions on whether anyone else thinks this should be fixed differently (or not at all). N.B. this also changes the behaviour of mt_rand to now accept min > maxYour fix seems fine for rand() but less so for mt_rand(). Applying this fix will break much less mt_rand()-using code than not applying it will break rand()-using code. From that point of view, applying it is the better choice. Otoh, it's like copy-pasting a weird old bug from rand() to mt_rand(). The plan was to make rand() alias mt_rand(). Now I'm not sure that's a smart plan. Tom