3v4l.org

run code in 300+ PHP versions simultaneously
<?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; } $ret .= $chars[$byte % $strlen]; if (strlen($ret) >= $len) { return $ret; } } } echo password();

preferences:
47.36 ms | 402 KiB | 5 Q