Secondo sorgenti 7.2.7 di PHP , il La funzione str_shuffle utilizza php_string_shuffle che fa
while (--n_left) {
rnd_idx = php_rand();
RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX);
if (rnd_idx != n_left) {
temp = str[n_left];
str[n_left] = str[rnd_idx];
str[rnd_idx] = temp;
}
}
Quindi suppongo che ti piacerebbe conoscere i valori intermedi di rnd_idx (poiché php_rand() è un alias di php_mt_rand() ).
Ma RAND_RANGE è una macro definita come #define RAND_RANGE(__n, __min, __max, __tmax) (__n) = php_mt_rand_range((__min), (__max)) , quindi il 1 ° valore di php_rand() è già perso all'istante.
Quindi, non otterrai l'elenco di tutti i valori intermedi mt_range() .
Tuttavia, sapendo che l'algoritmo sembra essere at each round, swap the current letter with a random letter before in the input string; the 1st round takes the last letter as the current one; the next round takes the letter previous current letter as the new current letter , puoi ottenere il valore mt_rand ragionando all'indietro.
Se ABCD è il valore di input e BADC è il risultato, significa che i valori erano 2;2;0 ( ABCD = > ABDC = > ABDC = > BADC ) ma non conosci ancora il valore delle chiamate "perse" in php_mt_rand . Quindi la sequenza di mt_rand era in realtà ?;2;?;2;?;0 che corrisponde al seme 4 e 25 : se fai mt_srand(4); echo str_shuffle('ABCD'); otterrai BADC e lo stesso se il tuo seme è impostato su 25 . Avresti bisogno di una lunga catena di caratteri unici per ottenere una sequenza abbastanza lunga da corrispondere a un solo seme.