ID:               40724
 Updated by:       [EMAIL PROTECTED]
-Summary:          srand returns different results in 5.2.1 than in
                   previous versions
 Reported By:      dave at dmorg dot org
-Status:           Bogus
+Status:           Open
 Bug Type:         Math related
 Operating System: linux, windows
 PHP Version:      5.2.1
 New Comment:

It's still a BC break. I know, from a maintainer's standpoint, how
infinitely annoying small changes like this are. But this change breaks
code, with no way to go back to the old behavior. The fact that no one
promised that the random number generator wouldn't change is a false
framing of the question - no one said that the random number generator
_would_ change either. In fact the docs for mt_rand specifically
encourage using it because, as compared to c library rand functions, it
has "known characteristics".

I think this should be reverted or somehow the old algorithm should be
made available, but at the very least this needs to have a changelog
entry, and http://php.net/mt-rand should be updated to note that you
can't rely on mt_srand() taking a seed consistently between PHP
versions. (I still think that defeats the "known characteristics"
statement also).


Previous Comments:
------------------------------------------------------------------------

[2007-03-21 14:47:12] [EMAIL PROTECTED]

>Mersenne Twister is still a psuedo-random system; 
>same seed should generate the same output.

And it does generate the same output.
Though nobody guranteed that in different PHP versions.

------------------------------------------------------------------------

[2007-03-21 14:36:17] [EMAIL PROTECTED]

Except that you can, if you pass it the same seed. Mersenne Twister is
still a psuedo-random system; same seed should generate the same output.
This is a subtle but non-trivial change for people generating
psuedo-cryptographic sequences.

(Ilia, don't tell me that MT isn't cryptographically secure, of course
it's not - that's not the point).

------------------------------------------------------------------------

[2007-03-05 23:57:53] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Random numbers are random, so you can't expect to get the same number 
out of a random number generator.

------------------------------------------------------------------------

[2007-03-05 07:52:38] dave at dmorg dot org

Description:
------------
I use srand to seed random numbers with student id numbers so that
whenever students relog in to an assignment, their questions have the
same input values and they can continue where they left off.

I am now getting different results than before. I'm not sure whether
this is an unintended consequence of some apparently unrelated code
change or whether it is intended. 



Reproduce code:
---------------
<?php

mt_srand(42);
echo mt_rand();
                
?>

produces 1387371436 under 4.*, 5.1.1. 5.1.4

produces 1354439493 under 5.2.1

Expected result:
----------------
I would expect results from the random number generator to be
consistent  when seeded with the same number

Actual result:
--------------
produces 1387371436 under 4.*, 5.1.1. 5.1.4

produces 1354439493 under 5.2.1


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=40724&edit=1

Reply via email to