Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94185 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83769 invoked from network); 21 Jun 2016 21:40:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Jun 2016 21:40:58 -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.215.43 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.215.43 mail-lf0-f43.google.com Received: from [209.85.215.43] ([209.85.215.43:32880] helo=mail-lf0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 08/17-43024-964B9675 for ; Tue, 21 Jun 2016 17:40:57 -0400 Received: by mail-lf0-f43.google.com with SMTP id f6so44852538lfg.0 for ; Tue, 21 Jun 2016 14:40:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=gPsJ6KxC4CXN0mvjOBIxP8xHI0RUicZJZiu8uTZ2KL0=; b=cL93BpsjwChMb5Fu+5/y6SrTMPoNVlooa1A3tTkqFndT/rs10ifYPPKRFgb0leuYf2 56CT1/2P0cIqEg52agMKAwfwQ1fbC96r1dZZih/4T3d74h0QMk1WQHzf7qrZfws81FS6 aTBSBJP8crQ2aOExSGh80DIuZVdIfOd9+z4Ihx4aMyLD6sHQpnPUTbbpSwHe9/bHgK9g 7JnosSmnz5Foziu5Ysw+jqxbzqonBMgZ1vzm1+1oYbE1lRmtlHGxk1GZPCU/b7wqZEFJ D7ti1lLGhll4vsa83CyKJ7eMbby94Ndwly2QlLekaFQbf6xuU9FMJ2k+92zvF6yfDI3O kDBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=gPsJ6KxC4CXN0mvjOBIxP8xHI0RUicZJZiu8uTZ2KL0=; b=YaBS3MdtfWlpQiMFcNkPG+x2BohiD/z5Jx9uz4rxT51ESa6y6S0objD+x8Y2dcNybr mkEcxeVSpxwpHDoTlfoU2XyNhpf3ZJN8PpoHlnPzrqTBPZ1IrdZLeYQDb9IbhHcapZgH itsBf6a2HG/VDzO7u2mY8csQ6ClYSoXtZt/x75TCYAnUnVupYDLIa5o5xnPaIAP18av7 ka1Z0Xc0SyApYVerRmsmUeffl62eZ43w5gsAWpKweudRF8jkPKibFX+czz0tuRJv4Pn7 dHHuz8uYjIiE17RlcjfuLbZd1Drknp2pXJqbIhYHOlgGMCh1hYzjgriokHg5NjZ47ex6 Kz7A== X-Gm-Message-State: ALyK8tIgk5rU2/5wf5z75OKh8LYvEUct5y/neazKBbQ/RzZb7NsDCMHaSMSWDUd20Y5R9Q== X-Received: by 10.28.56.68 with SMTP id f65mr5065322wma.58.1466545252875; Tue, 21 Jun 2016 14:40:52 -0700 (PDT) Received: from [192.168.1.191] ([2.25.96.65]) by smtp.googlemail.com with ESMTPSA id zb9sm24231264wjc.34.2016.06.21.14.40.52 for (version=TLSv1/SSLv3 cipher=OTHER); Tue, 21 Jun 2016 14:40:52 -0700 (PDT) To: internals@lists.php.net References: <2f92fa26-5f50-0e68-c1fc-de79f17c201e@fleshgrinder.com> Message-ID: <8b48f847-bbba-03f8-4b2e-9cd0841b484e@gmail.com> Date: Tue, 21 Jun 2016 22:40:51 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: <2f92fa26-5f50-0e68-c1fc-de79f17c201e@fleshgrinder.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] RNG fixes From: rowan.collins@gmail.com (Rowan Collins) Hi, I already wrote this message once, but it seems to have evaporated into the ether. So apologies if it reappears and this is revealed as a poor duplicate of it! On 21/06/2016 18:37, Fleshgrinder wrote: > I don't understand the drive to holding on to obviously faulty stuff. > Nikic proposed already to deprecate rand() and I am only saying that we > can go one step further and implement pcg_rand() in favor of mt_rand() > and deprecate mt_rand(). Probably not something we want to do in 7.1 > (because PCG needs some more time to mature) but something that we might > want to do on the road to PHP 8.0. I think the push to remove "cruft" would make more sense if the replacements were less obviously "cruft" in their own right. If I have to polyfill pcg_rand() on old servers and mt_rand() on new ones, I'd be tempted to just implement wtfbbq_rand() and have done with it, because the names, and even the algorithms they represent, are pretty meaningless to me. As with libsodium, I think we should avoid replacing one set of overly-specific implementations with another, and saying "this time we've got it right". Instead, we should look at what people actually want the functions *for*, and hide the implementation as much as possible. For instance, for reproducible (seedable) random sequences, how about a function random_int_sequence($seed, $min, $max) which returns a generator, so you could write "$user_seq = random_int_sequence($user_seed, 0, 10); $user_pick = $user_seq();" Or maybe it could return a closure, or an object - either way, something to replace the global state of (mt_)srand. Perhaps a random_int_fast() function with big warnings that it's not to be trusted for crypto, but performs really well if all you're doing is picking which image banner to show on your home page. Use whatever RNG you want under the hood, make a declaration of whether or not it's stable cross-platform and cross-version, and give users an actual reason to change their code. Then consider other use cases: a better uniqid(), shuffling, maybe built-in UUID support... Then, IF the new APIs become popular, we can come back to talking about removing rand() and mt_rand(), because we'll have replaced them with something substantially better, not just another variant on the same thing. Regards, -- Rowan Collins [IMSoP]