Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98080 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1317 invoked from network); 31 Jan 2017 13:08:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Jan 2017 13:08:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.17.21 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.17.21 mout.gmx.net Received: from [212.227.17.21] ([212.227.17.21:58955] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8A/16-51557-45C80985 for ; Tue, 31 Jan 2017 08:08:37 -0500 Received: from [192.168.2.109] ([217.82.227.219]) by mail.gmx.com (mrgmx102 [212.227.17.168]) with ESMTPSA (Nemesis) id 0LsOsW-1cRuNG2k12-011yU7; Tue, 31 Jan 2017 14:07:14 +0100 To: Andrea Faulds , internals@lists.php.net References: Message-ID: Date: Tue, 31 Jan 2017 14:07:35 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:lTgveC77tKD0/K6zZF0ZHVCqP0S+ZKVfKi5qAoDDC96ZIms4e4J EV/NzS37jqKFypiUEWKA7hizYB1l5ftqwil5T568+CgdvfeMXobaYNobh6fPgr2nkJTF9KM M5J7KUMnSevpCukhg7k0zm3OkIRft2TXoW7sw4uSU3H2PIk3nvBB137jwqFjnkx4A5uTJCW TAwqQX/nqvnxgu4mCAhng== X-UI-Out-Filterresults: notjunk:1;V01:K0:xCQz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W7P8Vn8+NmYW1Z6z7k14+oGoerq5dYHKEf8YRs0tiXRTTXwGTbYxa2g== Subject: Re: Reseeding rand()/mt_rand() From: cmbecker69@gmx.de ("Christoph M. Becker") On 30.01.2017 at 17:29, Andrea Faulds wrote: > Christoph M. Becker wrote: > >> Just a quick idea: >> >> > >> class PNRG { >> public function __construct($seed = null) {…} >> public function get() {…} >> } > > I've long favoured an API along these lines. One size does not fit all, > you need two APIs for (non-crytographic) random numbers: > - automatically-seeded, non-reproducible numbers (a global function like > rand()) > - manually-seeded, reproducible number sequences (objects) > > Currently we mix these two, and it's a mess. The easy solution would be > a random number-generating object like you propose, to cover the second > use-case. We could also introduce a non-manually-seedable global PRNG > also, if desired. Perhaps as a static method of that class. > > One thought: it'd be nice if you had two different methods, one that > mutates in places, and one that doesn't, i.e.: > > $prng1 = new PRNG(SEED); > [$randomNumber, $prng2] = $prng2->getWithNewPRNG(); > > v.s.: > > $prng = new PRNG(SEED); > $randomNumber = $prng->get(); > $randomNumber2 = $prng->get(); Thanks, Andrea! I like all your suggestions, and I'd be happy to see a respective RFC – unfortunately, I won't have time to do this myself in the near future. -- Christoph M. Becker