Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85776 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73799 invoked from network); 12 Apr 2015 19:36:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Apr 2015 19:36:12 -0000 Authentication-Results: pb1.pair.com header.from=leafnode@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=leafnode@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.181 as permitted sender) X-PHP-List-Original-Sender: leafnode@gmail.com X-Host-Fingerprint: 209.85.217.181 mail-lb0-f181.google.com Received: from [209.85.217.181] ([209.85.217.181:36643] helo=mail-lb0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CA/01-62743-A29CA255 for ; Sun, 12 Apr 2015 15:36:11 -0400 Received: by lbbqq2 with SMTP id qq2so44826484lbb.3 for ; Sun, 12 Apr 2015 12:36:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:subject:message-id:date:to:mime-version; bh=B1wv87vhv4V/ajtrFaD+elp8D/ZRtWZ7+7N1n1IkqNw=; b=Xr9A18hU2swNIj+w71YV3s5TclIh8SXH4SHocKnhIEO6y5asxuGIHwXRzADImtXu++ xJkR+/iFIZLs9J5LUNqui8fCpwHpnOu5RSOsJfM1KpaJCI4QXdqUKziB/hhRbWjgY8KH Z46S/ZWK79c4Oa26yrCVNljylwSSnYYZJakL+qMrZ26U2+hym3YC+4b5oNWDWw1eg3Fg K1TVbMEkAoDt11cTAzbek7DaMggqx/ig+i9dbV+pJZlHgY6Jpv/e6CrG4bnxo5p6oxrz MNZK/xS8DKXOMV4n3nVDqYkbyyiM6z0lNAsd3TWn27BR0wTg4udtmkeKNnVg42dAU2+u tAvw== X-Received: by 10.152.27.35 with SMTP id q3mr10101140lag.24.1428867367561; Sun, 12 Apr 2015 12:36:07 -0700 (PDT) Received: from [192.168.1.148] (89-65-44-126.dynamic.chello.pl. [89.65.44.126]) by mx.google.com with ESMTPSA id nz1sm1184298lbb.44.2015.04.12.12.36.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 12 Apr 2015 12:36:06 -0700 (PDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_40430894-FCA0-491F-AFAC-711FD787FE7A" Message-ID: <2FECEA44-6299-4984-8789-C0A107D88C4B@gmail.com> Date: Sun, 12 Apr 2015 21:36:04 +0200 To: =?utf-8?Q?Leszek_Krupi=C5=84ski?= Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) X-Mailer: Apple Mail (2.2098) Subject: $max > getmaxrand() for rand() call From: leafnode@gmail.com (Leszek Krupinski) --Apple-Mail=_40430894-FCA0-491F-AFAC-711FD787FE7A Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hello A friend of mine reported something that seemed like a bug = (https://bugs.php.net/bug.php?id=3D69396 = ) - to sum up: if you provide = $max parameter that is larger than OS-provided getmaxrand(), the result = will be artificially stretched, which in result leads to some values not = appearing at all. That=E2=80=99s troublesome if for instance some people = use that function to choose random server for a service, and the = stretched result wouldn=E2=80=99t return even values at all. The very same thing is reported as a first comment for the rand() = function in PHP manual - and that comment is 8 years old. Apparently this is a sort-of correct behaviour, but it should be taken = care of. I see 4 ways: 1. Document the behaviour and keep it that way. 2. Allow that behaviour, document it, but if $max > getrandmax(), emit a = warning/notice. 3. Disallow that, document, and return false (as some other functions do = when arguments are incorrect). 4. Disallow that, but trim $max to getrandmax(), and emit a = warning/notice. I think that this behaviour should not be allowed, because in the end it = generates incorrect results, doesn=E2=80=99t matter if the user would = like that or not. What do you think about this issue? =E2=80=94Leszek= --Apple-Mail=_40430894-FCA0-491F-AFAC-711FD787FE7A--