Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98104 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60667 invoked from network); 1 Feb 2017 01:47:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Feb 2017 01:47:29 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@ohgaki.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@ohgaki.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ohgaki.net designates 180.42.98.130 as permitted sender) X-PHP-List-Original-Sender: yohgaki@ohgaki.net X-Host-Fingerprint: 180.42.98.130 ns1.es-i.jp Received: from [180.42.98.130] ([180.42.98.130:59542] helo=es-i.jp) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C7/BF-51557-F2E31985 for ; Tue, 31 Jan 2017 20:47:28 -0500 Received: (qmail 39544 invoked by uid 89); 1 Feb 2017 01:47:23 -0000 Received: from unknown (HELO mail-wm0-f43.google.com) (yohgaki@ohgaki.net@74.125.82.43) by 0 with ESMTPA; 1 Feb 2017 01:47:23 -0000 Received: by mail-wm0-f43.google.com with SMTP id v77so15681396wmv.0 for ; Tue, 31 Jan 2017 17:47:23 -0800 (PST) X-Gm-Message-State: AIkVDXL1DYfeqpjzHQneVZiZyLaxDK1RogdjzM1Xu8tlDys/9fqGrhfgt3htt7G5pjhMJzEheGBFXYEdhHk3Bg== X-Received: by 10.28.163.194 with SMTP id m185mr561174wme.122.1485913636807; Tue, 31 Jan 2017 17:47:16 -0800 (PST) MIME-Version: 1.0 Received: by 10.195.12.8 with HTTP; Tue, 31 Jan 2017 17:46:36 -0800 (PST) In-Reply-To: <98.BB.51557.D38F0985@pb1.pair.com> References: <98.BB.51557.D38F0985@pb1.pair.com> Date: Wed, 1 Feb 2017 10:46:36 +0900 X-Gmail-Original-Message-ID: Message-ID: To: Andrea Faulds Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=94eb2c0641607d323205476e3a75 Subject: Re: [PHP-DEV] Re: Reseeding rand()/mt_rand() From: yohgaki@ohgaki.net (Yasuo Ohgaki) --94eb2c0641607d323205476e3a75 Content-Type: text/plain; charset=UTF-8 Hi all, On Wed, Feb 1, 2017 at 5:48 AM, Andrea Faulds wrote: > Yasuo Ohgaki wrote: > >> My current objective is to make existing API to work, so resource may be >> used >> to set/get PRNG state. >> > > I would prefer it if we not introduce a new usage of resources. An object > would suffice. > > *** Initialize and Create new PRNG state resource *** >> resource mt_srand([int|string $seed]) >> >> resource: MT rand state resource. >> $seed: I would like to allow large seed like Python and Ruby. >> When seed is string, use all bits for MT rand state >> initialization. >> Example usage: mt_srand(random_bytes(2000)); >> >> *** Get random number from state resource *** >> int mt_rand() // System state >> int mt_rand(resource $state) // Specified user state >> int mt_rand(int $min , int $max [,resource $state]) // Specified user >> state >> if $state is passed >> > > While we could retrofit this into the existing API, it would be cleaner > and friendlier to provide a new one based on objects. Object based implementation is nicer. I agree. I like multi paradigm programming also. We should provide API that users can adopt with minimal cost. IMHO. Therefore, I would like to provide working PRNG for both procedural and object based. I wrote new RFC that fixes issues discussed here. https://wiki.php.net/rfc/improve_predictable_prng_random I used RandomState object so that OO based Random API can use it seamlessly in the future. Comments are appreciated! Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --94eb2c0641607d323205476e3a75--