Last active
June 25, 2020 10:34
-
-
Save alichry/ef8c049ced20d59c03b713498706fe6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; |
Author
alichry
commented
Jun 25, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment