Method 1: Use/dev/urandom
[[email protected] shell]# tr -dc "0-9" < /dev/urandom | head -c 10 # Generate 10 Digital 5798734885[[email protected] shell]# [[email protected] shell]# [[email protected] shell]# tr -dc "A-Z" < /dev/urandom | head -c 10 #生成10个小写字符xxcudpzyfu [[Email protected] shell ]# [[email protected] shell]# tr -dc "A-Z" < /dev/urandom | head -c 10 #生成10个大写字符XFDBEFCDKV [[email protected] shell]# [[email protected] shell]# tr -dc "0-9,a-z" < /dev/urandom | head -c 10 #生成数字和字符的组合ryjhjhnpyd [[email protected] shell]#
Method Two: Use Date +%s
Randomly generate a bunch of numbers
[Email protected]:/home/dell/shell# date +%s |cksum |cut-d ""-F 1 1934689009
Expansion: Randomly generates a number within 10
[Email protected]:/home/dell/shell# echo "' Date +%s |cksum |cut-d" "-F 1 '%100" |bc81
2. Randomly generate a string of lowercase letters
[Email protected]:/home/dell/shell# Date +%s| md5sum | Tr-dc "A-Z" |head-c 10[email protected]:/home/dell/shell#
3. Randomly generated combinations of numbers and letters
[Email protected]:/home/dell/shell# Date +%s| md5sum | Head-c 1067e
Method Three: Using OpenSSL rand
[Email protected]:/home/dell/shell# OpenSSL rand-base64 40c6s7wofbx3s4imkzb9mhdkcywzyreae0lauqplpcaex+kf8hakxorw==
This article is from the "Hello World" blog, so be sure to keep this source http://237085.blog.51cto.com/227085/1959461
How the shell generates random numbers