https://github.com/php/php-src/blob/master/ext/standard/string.c#L5630```c
PHPAPI bool php_binary_string_shuffle(const php_random_algo *algo, php_random_status *status, char *str, zend_long len) /* {{{ */
{
int64_t n_elems, rnd_idx, n_left;
char temp;
/* The implementation is stolen from array_data_shuffle */
/* Thus the characteristics of the randomization are the same */
n_elems = len;
if (n_elems <= 1) {
return true;
}
n_left = n_elems;
while (--n_left) {
rnd_idx = algo->range(status, 0, n_left);
if (EG(exception)) {
return false;
}
if (rnd_idx != n_left) {
temp = str[n_left];
str[n_left] = str[rnd_idx];
str[rnd_idx] = temp;
}
}
return true;
}
```
https://github.com/php/php-src/blob/master/ext/random/random.c#L423```c
PHPAPI zend_long php_mt_rand_range(zend_long min, zend_long max)
{
return php_random_algo_mt19937.range(php_random_default_status(), min, max);
}
```
可以看出,都是调用某个算法的 range 函数,所以 str_shuffle 和 mt_rand 的底层都是相似的,差别可能就是算法不一样