RE: [PHP-DEV] [RFC] Add Random Extension (before: Add Random class)
| From: | CHU Zhaowei | Date: | Fri, 02 Jul 2021 19:15:01 +0000 |
| Subject: | RE: [PHP-DEV] [RFC] Add Random Extension (before: Add Random class) | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-115277@lists.php.net to get a copy of this message | ||
>> "Why does this method exist at all? When would you use it instead of
>> getInt()?"
>>
> The case for this would be if you want to get a raw unrounded random number sequence as a
> number. The situations where this is required would certainly be limited, but it would be nice to
> have. (At least, I know of several production codes that use the result of mt_rand() with no
> arguments.)
These two methods confused me at first as well, but I think it's ok with me after I check the
documentation of mt_rand(), which also supports calling without range. So, compatibility is one of
the reasons why this method exists, although I still feel we should find a better name for them.
They are too similar now, you won't be able to tell the difference without looking into the
documentation or source code.
Besides the name issue, I have another question for nextInt(). What's the range of its return?
It's not clear in the RFC. The range of mt_rand() (without min and max) is 0 to
mt_getrandmax(), so how about nextInt()? is there any equivalent method/constant for it?
Regards,
CHU Zhaowei