Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85778 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36329 invoked from network); 13 Apr 2015 10:00:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Apr 2015 10:00:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.177 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.217.177 mail-lb0-f177.google.com Received: from [209.85.217.177] ([209.85.217.177:36581] helo=mail-lb0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CD/60-30698-2C39B255 for ; Mon, 13 Apr 2015 06:00:34 -0400 Received: by lbbqq2 with SMTP id qq2so54456952lbb.3 for ; Mon, 13 Apr 2015 03:00:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=RlUGg9PAZKrd6ZW38frdIgWVOqBlwt1ReBM7RKG6ZhY=; b=pooOF3PWgr5eAmao8K086Rj8miNWWexaBwyNar7SBWKZ6JFbfozB3FwIFQbrZifWFZ kSL/Uv+rEUBorJCVoASBwojtPIulnjUNihWBfPGgYmQv0I5PnrmeEqNWZrMDG19POKP7 r1x+hLXv1HQgG2kDUZ8YbXzwkxk2tLyuS/8eNdsgnPCExwudDa+PuQTq1uk1eXiwnJ7G BTY1b45V9hY6HM9yJg58Ae2d0ZD83T17QTD3Fm+fWdpzTsdvEMlWhxpTzWLubOs4Yo2G M2dj/JokThX6jiFeBhvvbsdqnknziPkZo+atizOt7rrJt4DhpRRbxCrpbF6TT/24bAJa veHw== X-Received: by 10.152.44.225 with SMTP id h1mr12479979lam.5.1428919230699; Mon, 13 Apr 2015 03:00:30 -0700 (PDT) Received: from [192.168.0.159] ([62.189.198.114]) by mx.google.com with ESMTPSA id w10sm1539990laz.6.2015.04.13.03.00.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Apr 2015 03:00:29 -0700 (PDT) Message-ID: <552B936E.1070804@gmail.com> Date: Mon, 13 Apr 2015 10:59:10 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: internals@lists.php.net References: <2FECEA44-6299-4984-8789-C0A107D88C4B@gmail.com> <552B36C7.7080102@gmail.com> In-Reply-To: <552B36C7.7080102@gmail.com> Content-Type: multipart/alternative; boundary="------------010309050106070605000209" Subject: Re: [PHP-DEV] $max > getmaxrand() for rand() call From: rowan.collins@gmail.com (Rowan Collins) --------------010309050106070605000209 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Stanislav Malyshev wrote on 13/04/2015 04:23: >> ) - 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’s troublesome if for instance some >> people use that function to choose random server for a service, and >> the stretched result wouldn’t return even values at all. > How many servers you've got? Also, why not use mt_rand()? It has max of > 2^^31, if you have more servers than that you probably have very > uncommon use case :) 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() instead. Regards, -- Rowan Collins [IMSoP] --------------010309050106070605000209--