Re: rand(), mt_rand() and limits
| From: | Rasmus Lerdorf | Date: | Mon, 12 Jan 2015 09:06:46 +0000 |
| Subject: | Re: rand(), mt_rand() and limits | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-80412@lists.php.net to get a copy of this message | ||
On 01/11/2015 06:05 PM, Stanislav Malyshev wrote:
> Hi!
>
>> Also, FWIW, anyone who used the Suhosin patch couldn’t use srand()
>> because it disabled it.
>
> And? You can disable any function in PHP, that doesn't mean anything.
>
>> Because if we don’t break it, people will continue to rely on it, and
>> this binds our hands for future versions.
>
> Sorry, that doesn't sound even remotely like a good reason. It doesn't
> provide any benefit to the user, but produces problems for those who use
> it. The gain for the users is zero, the added trouble - for those who
> use the feature - is substantial.
>
>> Also, those people will have their code break anyway if they upgrade
>> their OS and it changes its random number generator.
>
> If they used mt_rand that is not true. And OS RNG changes are not that
> frequent. E.g. the manual for srand on Mac (and, likely, all BSD) says:
>
> The srand() function sets its argument seed as the seed for a new
> sequence of pseudo-random numbers to be returned by rand().
> These sequences are repeatable by calling srand() with the same seed value.
>
> The Linux manual says:
>
> The srand() function sets its argument as the seed for a new
> sequence of pseudo-random integers to be returned by rand().
> These sequences are repeatable by calling srand() with the same seed value.
>
> I would say the expectation here is pretty clear.
Yes, there is plenty of code out there that relies on srand()+rand()
returning a repeatable sequence of pseudo-random numbers. I have written
some myself. C devs are very familiar with this behaviour of srand.
There are tons of uses for this in game-related code. Think of something
like Minecraft world seeds. I bet Minecraft even uses this, or at least
the Java version of this, for generating its worlds. The worlds are
randomly generated, but if you get a particularly cool world you can
check the seed and give that seed to a friend and your friend can get
the same world generated. There are entire web sites dedicated to
sharing cool Minecraft seeds like this.
https://www.google.com/search?q=minecraft+seeds
-Rasmus
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc