Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random string: does php str_shuffle add entropy

Tags:

php

random

I am generating random string with this:

 $characters = '0123456789QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm';  
$cl = strlen($characters) -1;
$id = '';
for ($p = 0; $p < $le; $p++) {N
    $id .= $characters[mt_rand(0, $cl)];
}

Now, if I do str_shuffle($id)will it add entropy i.e. make the string more random?

like image 649
Tero Lahtinen Avatar asked Nov 30 '25 03:11

Tero Lahtinen


1 Answers

If you want password entropy, might I suggest openssl_random_pseudo_bytes($length) or mcrypt_create_iv($length)?

For a custom character set, look up binhex() and convBase() which should be in the PHP manual comments for base_convert()

like image 97
Scott Arciszewski Avatar answered Dec 02 '25 18:12

Scott Arciszewski