- chr: documentation ( source)
- mt_rand: documentation ( source)
- mt_srand: documentation ( source)
- str_replace: documentation ( source)
- base64_encode: documentation ( source)
<?php
mt_srand(42);
for ($i = 0; $i < 20; $i++) {
echo_key();
}
function echo_key() {
$buf = rand_buffer(48);
echo base64_encode($buf) . "\n";
echo base64_urlencode($buf) . "\n";
}
function base64_urlencode($buf) {
return str_replace(array('+', '/', '='), array('-', '_', ''), base64_encode($buf));
}
function rand_buffer($n) {
//try {
// $buf = openssl_random_pseudo_bytes($n);
//} catch (Exception $e) {
$buf = "";
for ($i = 0; $i < $n; $i++) {
$buf .= chr(mt_rand(0, 255));
}
//}
return $buf;
}