根据长度生成随机文本

长度为“$ 1”的随机文本没有无用的cat命令。
.

0

linux命令:genRandomText() { tr -cd '[:alpha:]' < /dev/urandom | head -c "$1"; } } "$1"; -c head | /dev/urandom < '[:alpha:]' -cd tr { genRandomText() genRandomText() { tr -cd '[:alpha:]' < /dev/urandom | head -c "$1"; }rootopen.com
linux命令:genRandomText() { tr -cd '[:alpha:]' < /dev/urandom | head -c "$1"; } } "$1"; -c head | /dev/urandom < '[:alpha:]' -cd tr { genRandomText() genRandomText() { tr -cd '[:alpha:]' < /dev/urandom | head -c "$1"; }rootopen.com
tlcg 2017-12-25 19:30:48
输出
替代方案1 根据长度生成随机文本

这是我的版本。这有点冗长,但我更喜欢它,因为它全是Bash。.

linux命令:genRandomText() { x=({a..z}); for(( i=0; i<$1; i++ )); do printf ${x[$((RANDOM%26))]}; done; printf "\n"; } } "\n"; printf done; ${x[$((RANDOM%26))]}; printf do )); i++ i<$1; i=0; for(( x=({a..z}); { genRandomText() genRandomText() { x=({a..z}); for(( i=0; i<$1; i++ )); do printf ${x[$((RANDOM%26))]}; done; printf "\n"; }rootopen.com
linux命令:genRandomText() { x=({a..z}); for(( i=0; i<$1; i++ )); do printf ${x[$((RANDOM%26))]}; done; printf "\n"; } } "\n"; printf done; ${x[$((RANDOM%26))]}; printf do )); i++ i<$1; i=0; for(( x=({a..z}); { genRandomText() genRandomText() { x=({a..z}); for(( i=0; i<$1; i++ )); do printf ${x[$((RANDOM%26))]}; done; printf "\n"; }rootopen.com
.
输出
替代方案2 根据长度生成随机文本

使用urandom获取随机数据,用tr删除非字母并打印第一个$ 1字节。.

linux命令:genRandomText() { cat /dev/urandom|tr -dc 'a-zA-Z'|head -c $1 } } $1 -c 'a-zA-Z'|head -dc /dev/urandom|tr cat { genRandomText() genRandomText() { cat /dev/urandom|tr -dc 'a-zA-Z'|head -c $1 }rootopen.com
linux命令:genRandomText() { cat /dev/urandom|tr -dc 'a-zA-Z'|head -c $1 } } $1 -c 'a-zA-Z'|head -dc /dev/urandom|tr cat { genRandomText() genRandomText() { cat /dev/urandom|tr -dc 'a-zA-Z'|head -c $1 }rootopen.com
.
输出
替代方案3 根据长度生成随机文本

如果你没有seq,你可以使用perl。.

linux命令:genRandomText() { perl -e '$n=shift; print chr(int(rand(26)) + 97) for 1..$n; print "\n"' $1;} $1;} "\n"' print 1..$n; for 97) + chr(int(rand(26)) print '$n=shift; -e perl { genRandomText() genRandomText() { perl -e '$n=shift; print chr(int(rand(26)) + 97) for 1..$n; print "\n"' $1;}rootopen.com
linux命令:genRandomText() { perl -e '$n=shift; print chr(int(rand(26)) + 97) for 1..$n; print "\n"' $1;} $1;} "\n"' print 1..$n; for 97) + chr(int(rand(26)) print '$n=shift; -e perl { genRandomText() genRandomText() { perl -e '$n=shift; print chr(int(rand(26)) + 97) for 1..$n; print "\n"' $1;}rootopen.com
.
输出
替代方案4 根据长度生成随机文本

是否需要获取一些长度为特定字符数的文本?使用此功能轻松生成它!看起来不漂亮,但确实可以用于测试目的!.

linux命令:genRandomText() { a=( a b c d e f g h i j k l m n o p q r s t u v w x y z );f=0;for i in $(seq 1 $(($1-1))); do r=$(($RANDOM%26)); if [ "$f" -eq 1 -a $(($r%$i)) -eq 0 ]; then echo -n " ";f=0;continue; else f=1;fi;echo -n ${a[$r]};done;echo"";} ${a[$r]};done;echo"";} -n f=1;fi;echo else ";f=0;continue; " -n echo then ]; 0 -eq $(($r%$i)) -a 1 -eq "$f" [ if r=$(($RANDOM%26)); do $(($1-1))); 1 $(seq in i );f=0;for z y x w v u t s r q p o n m l k j i h g f e d c b a a=( { genRandomText() genRandomText() { a=( a b c d e f g h i j k l m n o p q r s t u v w x y z );f=0;for i in $(seq 1 $(($1-1))); do r=$(($RANDOM%26)); if [ "$f" -eq 1 -a $(($r%$i)) -eq 0 ]; then echo -n " ";f=0;continue; else f=1;fi;echo -n ${a[$r]};done;echo"";}rootopen.com
linux命令:genRandomText() { a=( a b c d e f g h i j k l m n o p q r s t u v w x y z );f=0;for i in $(seq 1 $(($1-1))); do r=$(($RANDOM%26)); if [ "$f" -eq 1 -a $(($r%$i)) -eq 0 ]; then echo -n " ";f=0;continue; else f=1;fi;echo -n ${a[$r]};done;echo"";} ${a[$r]};done;echo"";} -n f=1;fi;echo else ";f=0;continue; " -n echo then ]; 0 -eq $(($r%$i)) -a 1 -eq "$f" [ if r=$(($RANDOM%26)); do $(($1-1))); 1 $(seq in i );f=0;for z y x w v u t s r q p o n m l k j i h g f e d c b a a=( { genRandomText() genRandomText() { a=( a b c d e f g h i j k l m n o p q r s t u v w x y z );f=0;for i in $(seq 1 $(($1-1))); do r=$(($RANDOM%26)); if [ "$f" -eq 1 -a $(($r%$i)) -eq 0 ]; then echo -n " ";f=0;continue; else f=1;fi;echo -n ${a[$r]};done;echo"";}rootopen.com
.
输出

评论

相关推荐

如果你没有seq,你可以使用perl。

linux命令:genRandomText() { perl -e '$n=shift; print chr(int(rand(26)) + 97) for 1..$n; print "\n"' $1;} $1;} "\n"' print 1..$n; for 97) + chr(int(rand(26)) print '$n=shift; -e perl { genRandomText() genRandomText() { perl -e '$n=shift; print chr(int(rand(26)) + 97) for 1..$n; print "\n"' $1;}rootopen.com
linux命令:genRandomText() { perl -e '$n=shift; print chr(int(rand(26)) + 97) for 1..$n; print "\n"' $1;} $1;} "\n"' print 1..$n; for 97) + chr(int(rand(26)) print '$n=shift; -e perl { genRandomText() genRandomText() { perl -e '$n=shift; print chr(int(rand(26)) + 97) for 1..$n; print "\n"' $1;}rootopen.com
.

这是我的版本。它有点冗长,但我更喜欢它,因为它都是Bash。

linux命令:genRandomText() { x=({a..z}); for(( i=0; i<$1; i++ )); do printf ${x[$((RANDOM%26))]}; done; printf "\n"; } } "\n"; printf done; ${x[$((RANDOM%26))]}; printf do )); i++ i<$1; i=0; for(( x=({a..z}); { genRandomText() genRandomText() { x=({a..z}); for(( i=0; i<$1; i++ )); do printf ${x[$((RANDOM%26))]}; done; printf "\n"; }rootopen.com
linux命令:genRandomText() { x=({a..z}); for(( i=0; i<$1; i++ )); do printf ${x[$((RANDOM%26))]}; done; printf "\n"; } } "\n"; printf done; ${x[$((RANDOM%26))]}; printf do )); i++ i<$1; i=0; for(( x=({a..z}); { genRandomText() genRandomText() { x=({a..z}); for(( i=0; i<$1; i++ )); do printf ${x[$((RANDOM%26))]}; done; printf "\n"; }rootopen.com
.

使用urandom获取随机数据,删除带有tr的非字母并打印前 $1 字节。

linux命令:genRandomText() { cat /dev/urandom|tr -dc 'a-zA-Z'|head -c $1 } } $1 -c 'a-zA-Z'|head -dc /dev/urandom|tr cat { genRandomText() genRandomText() { cat /dev/urandom|tr -dc 'a-zA-Z'|head -c $1 }rootopen.com
linux命令:genRandomText() { cat /dev/urandom|tr -dc 'a-zA-Z'|head -c $1 } } $1 -c 'a-zA-Z'|head -dc /dev/urandom|tr cat { genRandomText() genRandomText() { cat /dev/urandom|tr -dc 'a-zA-Z'|head -c $1 }rootopen.com
.
共收录0条命令行
这里是记录和分享命令行的地方, 所有命令行都可以进行评论、提交替代方案.

推荐
    热门命令