Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98093 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37265 invoked from network); 31 Jan 2017 20:49:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Jan 2017 20:49:02 -0000 X-Host-Fingerprint: 137.50.184.77 oa-edu-184-77.wireless.abdn.ac.uk Received: from [137.50.184.77] ([137.50.184.77:22864] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 98/BB-51557-D38F0985 for ; Tue, 31 Jan 2017 15:49:02 -0500 Message-ID: <98.BB.51557.D38F0985@pb1.pair.com> To: internals@lists.php.net References: Date: Tue, 31 Jan 2017 20:48:58 +0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:49.0) Gecko/20100101 Firefox/49.0 SeaMonkey/2.46 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 137.50.184.77 Subject: Re: [PHP-DEV] Re: Reseeding rand()/mt_rand() From: ajf@ajf.me (Andrea Faulds) Hi, 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. -- Andrea Faulds https://ajf.me/