Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75577 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65666 invoked from network); 16 Jul 2014 05:14:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jul 2014 05:14:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.45 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.215.45 mail-la0-f45.google.com Received: from [209.85.215.45] ([209.85.215.45:48100] helo=mail-la0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1E/72-49478-D3A06C35 for ; Wed, 16 Jul 2014 01:14:37 -0400 Received: by mail-la0-f45.google.com with SMTP id ty20so260458lab.4 for ; Tue, 15 Jul 2014 22:14:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:from:date:message-id:subject:to:content-type; bh=Sz0ooOlSJaBoN4QrUEhuWpZp0yOMTfjxlvUNO3LYnDw=; b=c6TJcbfu1WzgRq0WL40l6bVBOz0L68NoIh+Qx2alO2TnGR+3VSkUDp3OxFiPtk8RlZ V++xjYmGzRdUl0Xe020o8rpU3SnXZUm90R2lQnry7NxE5T8KfGSjLXiM68sKZM+SGzMx /UdKfwmDKNtOvaSfiNWk2lP++j6p3gHlDGA/9mvvoDT+N8C63ZH5TlJNOTJkqeZtn1cH Uih4rwE2Zu9NlYUsEPgrL8QWVv51aa0IRdAdHfR1K/fN0BCtB8gZXO7NTVnwOg9rxtDf Ia5UbcNZjXMfyutmg27UcPGZHF6ZQxESKST1atPWZ6tcEeC8adMKh7YEKj9sBxjYZFm/ 7qqg== X-Received: by 10.152.115.229 with SMTP id jr5mr237862lab.94.1405487674283; Tue, 15 Jul 2014 22:14:34 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.128.202 with HTTP; Tue, 15 Jul 2014 22:13:54 -0700 (PDT) Date: Wed, 16 Jul 2014 14:13:54 +0900 X-Google-Sender-Auth: j4l7jfbvCHQ_oTn_6HhDs3SShq8 Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c354588fdcdd04fe4899b4 Subject: Use of php_mt_rand() rather than php_rand() From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c354588fdcdd04fe4899b4 Content-Type: text/plain; charset=UTF-8 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 --001a11c354588fdcdd04fe4899b4--