I am trying to port a piece of code from perl to php. The perl code snippet is part of akamai's video on demand link generation script. The script generates seed based on the location / URL of the video file (which will always be constant for a single URL). And then it is used in generating serial ID for stream (which is basically a random number between 1 and 2000 using the seed). Here is the perl code.
$seed=6718;
srand($seed);
print(int(rand(1999)) + 1); // return 442 every time
And the converted PHP code is:$seed=6718;
srand($seed);
echo(rand(0, 1999) + 1); //returns 155 every time
Does php rand behaves differently than perl one?
rand
返回的一致数字集合指向代码中更深层次的问题。我希望这只是一个好奇心,而不是某种移植问题。如果是后者,请从 Perl 和 PHP 进行一次“随机”数字转储,进行必要的映射,然后消除对非随机随机数的依赖。 - unpythonicrand()
函数。它们非常依赖于系统,并且除非另有说明,否则可能会发生变化。 - Ven'Tatsu