- Notifications
You must be signed in to change notification settings - Fork8k
Closed
Description
Description
The following code:
<?phpfunctionfoo():int{srand(0);$bar =rand(0,1023);var_dump($bar);return$bar;}var_dump(foo() ===foo());
Resulted in this output:
int(684)int(684)bool(true)
But I expected this output instead:
int(23)int(756)bool(false)
But this code:
<?phpfunctionfoo():int{srand();$bar =rand(0,1023);var_dump($bar);return$bar;}var_dump(foo() ===foo());
Works fine:
int(722)int(132)bool(false)
https://www.php.net/manual/en/function.srand.php
Seeds the random number generator with seed or with a random value if seed is 0.
It's seems like srand(0) process 0 as new seed value instead 0 must reset seed to new random value.
PHP Version
PHP 8.2.0
Operating System
Win 11 build 25272 (insider)