Random: Add random string generator.
This commit is contained in:
parent
fb0050a0a6
commit
77bfe23b2b
|
@ -1,5 +1,16 @@
|
||||||
{ ... }: {
|
{ ... }: {
|
||||||
text = ''
|
text = ''
|
||||||
|
# Generate random string.
|
||||||
|
# Usage: random <LENGTH>
|
||||||
|
function random() {
|
||||||
|
local length="''${1}"
|
||||||
|
if [[ "''${length}" = "" ]]; then
|
||||||
|
help random
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
head /dev/urandom | tr -dc A-Za-z0-9 | head -c''${length}
|
||||||
|
}
|
||||||
|
|
||||||
# Picks a random file or directory.
|
# Picks a random file or directory.
|
||||||
function random_file() {
|
function random_file() {
|
||||||
local IFS=$'\n'
|
local IFS=$'\n'
|
||||||
|
@ -8,7 +19,7 @@
|
||||||
((total--))
|
((total--))
|
||||||
local index=$(shuf -i 0-''${total} -n 1)
|
local index=$(shuf -i 0-''${total} -n 1)
|
||||||
|
|
||||||
echo ''${dirs[$index]}
|
printf "%s" ''${dirs[$index]}
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue