Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:15490 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75662 invoked by uid 1010); 18 Mar 2005 19:37:26 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 75647 invoked by uid 1007); 18 Mar 2005 19:37:26 -0000 To: internals@lists.php.net Content-Type: text/plain; format=flowed; delsp=yes; charset=koi8-r MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Date: Fri, 18 Mar 2005 21:42:42 +0300 Message-ID: User-Agent: Opera M2/7.60 (Win32, build 7141) X-Posted-By: 207.226.20.21 Subject: about mt_srand() function From: valyala@gmail.com ("Alexander Valyalkin") mt_srand() is used to seed initialisation vector (IV) for Mersenne Twister pseudorandom generator. But there is a "little" problem: the actual length of IV is 19968 bits, but mt_srand() accepts only 32-bit integers, which even reduced to 31 bit in function php_mt_srand() at /ext/standard/rand.c at string: php_uint32 x = (seed | 1U) & 0xFFFFFFFFU hint: lower bit of x is always equal to 1. So, entorpy of current implementation of MT generator is 31 bit (i.e. it can generate only 2^31-1 = 2147483647 different sequences), while its potential entropy is significant higher - up 19937 bit (it is impossible to imagine the number of different sequences 2^19937-1). So, I think, it will be good idea to change mt_srand() function in that way to accept not only one integer, but array of integers with length up to 624 elements to use Mersenne Twister generator in a full power. This change do not break backward compatibility. I can make nesessary changes and post unified diff, if you agree with me. -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/