Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75785 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13706 invoked from network); 21 Jul 2014 12:00:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Jul 2014 12:00:52 -0000 Authentication-Results: pb1.pair.com header.from=php@marc-bennewitz.de; sender-id=softfail Authentication-Results: pb1.pair.com smtp.mail=php@marc-bennewitz.de; spf=softfail; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain marc-bennewitz.de does not designate 80.237.132.171 as permitted sender) X-PHP-List-Original-Sender: php@marc-bennewitz.de X-Host-Fingerprint: 80.237.132.171 wp164.webpack.hosteurope.de Received: from [80.237.132.171] ([80.237.132.171:33853] helo=wp164.webpack.hosteurope.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 75/52-01457-2F00DC35 for ; Mon, 21 Jul 2014 08:00:51 -0400 Received: from dslb-178-005-231-020.pools.arcor-ip.net ([178.5.231.20] helo=[192.168.178.27]); authenticated by wp164.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) id 1X9CGs-0003CW-JV; Mon, 21 Jul 2014 14:00:46 +0200 Message-ID: <53CD00CD.1070807@marc-bennewitz.de> Date: Mon, 21 Jul 2014 14:00:13 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-bounce-key: webpack.hosteurope.de;php@marc-bennewitz.de;1405944051;c6880b47; Subject: Re: [PHP-DEV] Use of php_mt_rand() rather than php_rand() From: php@marc-bennewitz.de (Marc Bennewitz) Hi Yasuo, Some times ago I mailed my idea about refactoring random number generator API with min BC breaks but I didn't create an RFC right now. see http://marc.info/?l=php-internals&m=137772363015217 Marc On 16.07.2014 07:13, Yasuo Ohgaki wrote: > Hi all, > > There are few places that uses php_rand() currently. > > https://bugs.php.net/bug.php?id=66718 > http://lxr.php.net/search?q=php_rand&defs=&refs=&path=&hist=&project=PHP_5_5 > > These functions could use php_mt_rand() instead of php_rand(). > > php_rand() uses several rand functions > > 62PHPAPI long php_rand(TSRMLS_D) > 63{ > 64 long ret; > 65 > 66 if (!BG(rand_is_seeded)) { > 67 php_srand(GENERATE_SEED() TSRMLS_CC); > 68 } > 69 > 70#ifdef ZTS > 71 ret = php_rand_r(&BG(rand_seed)); > 72#else > 73# if defined(HAVE_RANDOM) > 74 ret = random(); > 75# elif defined(HAVE_LRAND48) > 76 ret = lrand48(); > 77# else > 78 ret = rand(); > 79# endif > 80#endif > 81 > 82 return ret; > 83} > > Most systems use random() which has cycle of 16 * ((2^31) - 1), > while MT rand has 2^19937-1. > > php_mt_rand() could be used where php_rand() is used. Unlike php_rand(), > php_mt_rand() does not check if it is seeded or not. It should be changed > to check seed status. > > The only BC issue I can think of is game that expects the same pseudo > random sequences. These apps may use mt_srand() to get fixed random > sequences and adjust their apps if it is needed. This is acceptable BC > for new releases. IMO. > > It would be good idea to support 64bit version of MT on 64bit platforms, > too. > > http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt64.html > > Any comments? > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net >