Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75611 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58031 invoked from network); 16 Jul 2014 23:03:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jul 2014 23:03:36 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.182 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.217.182 mail-lb0-f182.google.com Received: from [209.85.217.182] ([209.85.217.182:34302] helo=mail-lb0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DA/A3-37298-6C407C35 for ; Wed, 16 Jul 2014 19:03:35 -0400 Received: by mail-lb0-f182.google.com with SMTP id z11so1117476lbi.41 for ; Wed, 16 Jul 2014 16:03:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=pca1TCu4PS2OFEa+oq6VtO+GYwYeY2snq5jSw5lvFkM=; b=D+5RUfEliddVN8W9yqhx+C/aqv283qK1f4fjYBKzb+auHbo27BmBatvPMTsvq9v8Me GfN/kRCtUDDsN8Lb25c5YJKAUX0PSClsgxKp5m0bqGX4L69UNdo0FHCD2Wz5+/Q343/y FwhtoS2Fhyba2suFD8Tg8noCTa76iKaQe0vBi0qe1irGIEHOgjwiO+zyCsYn8ZzL6jYG yd79T8+nHuXvrWuKR0C0Yd7Z6A1cfL3HCaTrZuy3vzL8IwBPO4agEuhXmA4lkCi8PuzR IcJ1OV5OYVRkeoLKS/sYucDnqJXgqDygp6//GF+bW5ltYesl/O/+18bqyeoqSXoFQZ1K K3eQ== X-Received: by 10.152.120.195 with SMTP id le3mr28493195lab.16.1405551812020; Wed, 16 Jul 2014 16:03:32 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.128.202 with HTTP; Wed, 16 Jul 2014 16:02:51 -0700 (PDT) In-Reply-To: References: Date: Thu, 17 Jul 2014 08:02:51 +0900 X-Google-Sender-Auth: DhdzsrmntKTgzZ68qIvp48vA00I Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=089e01227abc78125904fe5788ba Subject: Re: Use of php_mt_rand() rather than php_rand() From: yohgaki@ohgaki.net (Yasuo Ohgaki) --089e01227abc78125904fe5788ba Content-Type: text/plain; charset=UTF-8 Hi all, On Wed, Jul 16, 2014 at 2:13 PM, Yasuo Ohgaki wrote: > 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? > RFC for this is created. https://wiki.php.net/rfc/use-php_mt_rand New rand() function name is TBD. I cannot think of good name, but I like rand_system(). rand() may stay as it is now also. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --089e01227abc78125904fe5788ba--