Skip to content

Instantly share code, notes, and snippets.

@alichry
Last active June 25, 2020 10:34
Show Gist options
  • Save alichry/ef8c049ced20d59c03b713498706fe6a to your computer and use it in GitHub Desktop.
Save alichry/ef8c049ced20d59c03b713498706fe6a to your computer and use it in GitHub Desktop.
<?php
function swap(&$o, $a, $b) {
$x = $o[$a];
$o[$a] = $o[$b];
$o[$b] = $x;
}
$letters = 'abcdefghijklmnopqrstuvwxyz';
$lettersUp = strtoupper($letters);
$digits = '0123456789';
$misc = '^+-()[]';
$alphabet = $letters . $lettersUp . $digits . $misc;
$len = strlen($alphabet);
$size = $argv[1] ?? 30;
for ($i = 0; $i < $size; $i++) {
for ($j = 0; $j < $len; $j++) {
$a = random_int(0, $len - 1);
$b = random_int(0, $len - 1);
swap($alphabet, $a, $b);
}
}
for ($i = 0; $i < $size; $i++) {
$k = random_int(0, $len - 1);
echo $alphabet[$k];
}
echo PHP_EOL;
@alichry
Copy link
Author

alichry commented Jun 25, 2020

curl -fSsL \
"https://gist.github.com/alichry/ef8c049ced20d59c03b713\
498706fe6a/raw/c7203d6e66a146f4f5e8b3c6027014246\
85c1685/php-rand-string.sh" | php -- 22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment