3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function password($len = 12) { $ret = ''; $chars = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'; $strlen = strlen($chars); $cutoff = floor(256 / $strlen) * $strlen; for (;;) { $byte = ord(openssl_random_pseudo_bytes(1)[0]); if ($byte >= $cutoff) { continue; } echo ($byte % $strlen).PHP_EOL; $ret .= $chars[$byte % $strlen]; if (strlen($ret) >= $len) { return $ret; } } } echo password();
Output for 7.1.7
54 55 48 52 19 13 50 17 23 0 35 30 78Z5uo3syaLF