note 97322 added to function.mt-srand

From: Date: Wed, 14 Apr 2010 14:33:45 +0000
Subject: note 97322 added to function.mt-srand
Groups: php.notes 
Request: Send a blank email to php-notes+get-168232@lists.php.net to get a copy of this message
I have spent the last couple of hours trying to track down a bug which affects mt_rand/rand and mt_srand/mt_rand. OS is Debian 5.0.4 "Lenny". PHP version is 5.3.2-0.dotdeb.1 with Suhosin-Patch (cli) (built: Mar 9 2010 11:42:01). I have tried to fix the issue by appending the following lines into the .htaccess / apache2 main config file: php_value suhosin.mt_srand.ignore Off php_value suhosin.srand.ignore Off This has helped a bit, stabilizing the beggining of the pseudo random number sequence, but the generator still fails after a fair number of iterations (roughly around 1K~3K. *** Removing the Suhosin extension has resolved this issue, I am waiting for an official extension build that will work with 5.3.x so that I can reattach it into the php configuration. *** Here is the code which ought to replicate the problem: $len = 100000; $min = 0; $max = 99; $t = (int)(microtime(true)*0xFFFF); $a = array(); srand( $t ); for ( $i = 0; $i < $len; $i ++ ) $a[$i] = rand( $min, $max ); $b = array(); srand( $t ); for ( $i = 0; $i < $len; $i ++ ) $b[$i] = rand( $min, $max ); for ( $i = 0; $i < $len; $i ++ ) if ( $a[$i] !== $b[$i] ) die( 'Pseudo-random sequence borked at #'.$i.'th iteration!'); echo 'Your pseudo-random sequencer is working correctly.'; exit( 0 ); ---- Server IP: 193.198.184.18 Probable Submitter: 213.202.106.62 ---- Manual Page -- http://www.php.net/manual/en/function.mt-srand.php Edit -- https://master.php.net/note/edit/97322 Del: integrated -- https://master.php.net/note/delete/97322/integrated Del: useless -- https://master.php.net/note/delete/97322/useless Del: bad code -- https://master.php.net/note/delete/97322/bad+code Del: spam -- https://master.php.net/note/delete/97322/spam Del: non-english -- https://master.php.net/note/delete/97322/non-english Del: in docs -- https://master.php.net/note/delete/97322/in+docs Del: other reasons-- https://master.php.net/note/delete/97322 Reject -- https://master.php.net/note/reject/97322 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168232) next »