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 $strlen; echo ($byte % $strlen).PHP_EOL; $ret .= $chars[$byte % $strlen]; if (strlen($ret) >= $len) { return $ret; } } } echo password();
Output for 7.1.7
571 578 576 5749 5755 5719 573 5713 5747 5730 5740 575 big28udoYFRf