I include the same "random.inc" in foo.php and bar.php. For everyone, I want reproducible “random” results.
So, in foo.php, I always need one set of numbers and / or keywords. In bar.php is different. Which should not change upon reboot. This is what I mean by the alias contant . And that’s why I sow by URL. However, I still get different results for single numbers, as well as for pickson array for every reboot. This is the complete php file:
<?
header('Content-Type: text/plain');
$seed = crc32( $_SERVER['REQUEST_URI'] );
echo "phpversion: ".phpversion()."\nseed: $seed\n";
srand( $seed );
echo ''.rand(0,100).' '.rand(0,100).' '.rand(0,100)."\n";
$values = array( '0'=>21,'1'=>89,'2'=>96,'3'=>47,'4'=>88 );
print_r( array_rand( $values, 3 ) );
?>
In the days of PHP4.1, it was (verified) possible to achieve a constant pseudo-random type. the documentation for the array array_rand describes as a function that, since the initialization of 4.2, occurs automatically. Perhaps this is a redefinition of any explicit seeding? (if so, maybe explicit sowing should raise the internal PHP flag, preventing automatic sowing?). Btw: mt_srand () and srand () do not work equally.
I would love to get my deterministic / constant pseudo-random inverse ...
Update: Solution below (Windows error and / or version 5.2)
source
share