# about mt_srand() function

- Thread: https://externals.io/message/15490
- Original archive: https://news-web.php.net/php.internals/15490
- Started by Alexander Valyalkin on 2005-03-18T18:42:42+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #15490 — Alexander Valyalkin — 2005-03-18T18:42:42+00:00

URL: https://externals.io/message/15490#15490

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/
