Generating random numbers in Linux can use the $random variable.
The Man Bash command looks at the explanation of the random.
Random each of the parameter is referenced, a random integer between 0 and 32767 is generated.
As you can see, the $RANDOM generates random numbers ranging from 0 to 32767.
If you want to generate a random number from 0 to 9, you can take a 10 modulo operation so that you can get a random number from 0 to 9.
[[email protected] ~]# echo $ (($RANDOM%10)) 8[[email protected] ~]# echo $ (($RANDOM%10)) 6[[email protected] ~]# echo $ (($RA NDOM%10)) 2[[email protected] ~]# echo $ (($RANDOM%10)) 0[[email protected] ~]# echo $ (($RANDOM%10)) 2[[email protected] ~]# echo $ ($RANDOM%10) 9[[email protected] ~]# echo $ (($RANDOM%10)) 6[[email protected] ~]# echo $ (($RANDOM%10)) 5
Randomly generate random numbers and verification codes from 1 to 10 bits
[[email protected] ~]# echo $ (($RANDOM)) | md5sum | Cut-c 1-105c55ba28b1[[email protected] ~]# echo $ (($RANDOM)) | md5sum | Cut-c 1-10fd6d39d9c1[[email protected] ~]# echo $ (($RANDOM)) | md5sum | Cut-c 1-102bfb089c18[[email protected] ~]# echo $ (($RANDOM)) | md5sum | Cut-c 1-1008089F9BE1
Use Md5sum to parse generated random numbers, and use Cut-c to split by character
You can use ${#var} When you are seeking the length of a variable.
[Email protected] ~]# A=abcdef[[email protected] ~]# echo ${#a}6
This article is from the "ssspure" blog, make sure to keep this source http://ssspure.blog.51cto.com/8624394/1862378
Shell Scripting Lesson Three: Generating random numbers