1.字符串截取
[code]key=\"qwertyuiopasdfghjklzxcvbnm1234567890\"read -p \"--------------num\" numrandpass(){rand=\"\"for i in `seq $num`donum=$[RANDOM%${#key}]local tmp=${key:num:1}rand=${rand}${tmp}doneecho $rand}
2.使用命令生成
2.1生成16进制随机字符串
[code][root@leo lianxi]# uuidgen8f377946-c2c6-494f-829f-06b484d8c113[root@leo lianxi]# openssl rand -hex 17d[root@leo lianxi]# openssl rand -hex 27596[root@leo lianxi]# openssl rand -hex 3ee2c0d[root@leo lianxi]# openssl rand -hex 4c66fad11
2.2生成含有特殊字符的
[code][root@leo lianxi]# openssl rand -base64 1Ng==[root@leo lianxi]# openssl rand -base64 2YTs=[root@leo lianxi]# openssl rand -base64 3Jw9n[root@leo lianxi]# openssl rand -base64 4rgXoBQ==[root@leo lianxi]# openssl rand -base64 59WNRQ6U=[root@leo lianxi]# openssl rand -base64 6dgu0GW5W[root@leo lianxi]# openssl rand -base64 106tui3IErbDhwuA==
[code][root@leo lianxi]# date +%s1590421845[root@leo lianxi]# date +%s%n1590421860
3.设备文件生成随机数
[code][root@leo lianxi]# tr -cd \'_a-zA-Z0-9\' < /dev/urandom | head -c 10oxKgM29Vll[root@leo lianxi]# tr -cd \'0-9\' < /dev/urandom | head -c 104706212081
4.hash值生成
[code][root@leo lianxi]# echo a | md5sum | cut -d \' \' -f160b725f10c9c85c70d97880dfe8191b3[root@leo lianxi]# sha256sum /etc/passwd | cut -d \' \' -f1651b40b91d69b0a08884923ad53d205fe1c14eafe0a5ee19deb4824540e88a59