法一:
[root@mode oldboy]# echo $RANDOM
21174
法二:
[root@mode oldboy]# openssl rand -base64 8
8CiQPMdoL2E=
[root@mode oldboy]# openssl rand -base64 8|md5sum
f152dc2f6dfdf5942c13b32e8b816635 -
法三:
[root@mode oldboy]# date +%s%N
1379338202258477000
法四:
[root@mode oldboy]# head /dev/urandom |cksum
1125309846 3918
法五:
[root@mode oldboy]# cat /proc/sys/kernel/random/uuid
60e2a0e6-1f13-46bf-b9c1-088eba1e3660
[root@mode oldboy]# cat /proc/sys/kernel/random/uuid |md5sum
405b0e6b7c100e595f8328a93bd69c1b -
法六:
[root@mode oldboy]# yum install expect -y
[root@mode oldboy]# rpm -qa expect
expect-5.43.0-8.el5
expect-5.43.0-8.el5
[root@mode oldboy]# mkpasswd -l 8
kmL#20nL
[root@mode oldboy]# mkpasswd |md5sum
dbaa82b8af52dd7d1edb276de56a545e -
去除特殊字符:
[root@mode oldboy]# mkpasswd -s 0
Egqnc34Hp
测试随机数的唯一性:
[root@mode oldboy]# echo $RANDOM|md5sum|cut -c 1-9|sort|uniq -c|sort -nk1
1 ceffba468
前面是1就是唯一的:
[root@mode oldboy]# for n in `seq 30`;do echo $RANDOM|md5sum|cut -c 1-9|sort|uniq -c|sort -nk1;done
1 ce57177b3
1 733b9d4a3
1 dbe743f06
1 d6e87f44e
1 0a7cfcb8c
1 730df42e6
1 1503efef7
1 513a67133
1 a21af8be4
1 78bbaed98
1 e144360bc
1 6e7ef8bef
1 9b4dc63bf
1 f6d0f2cd5
1 a5b4d1c5a
1 05f548c50
1 a3ca5109c
1 7f96127dd
1 92504d280
1 2ee172f16
1 9bcf1aad6
1 248593824
1 6d97f99f5
1 18280adea
1 558c9ab52
1 3c71a3f34
1 c19b4f838
1 24128b038
1 004f43651
1 af92772db
[root@mode oldboy]# for n in `seq 30`;do date +%s%N|md5sum|cut -c 1-9|sort|uniq -c|sort -nk1;done
1 e15176859
1 c18bffb74
1 a068141d6
1 f4004461a
1 edae1c57d
1 9bbeea47d
1 4eed91f2c
1 4fc982a96
1 37245f358
1 112345ccf
1 40a27a5fc
1 87b75f076
1 a6aa01aed
1 185b31008
1 5bc9d2d30
1 4e0be25bc
1 3bcc6a403
1 89c7f91f0
1 646ea7e8e
1 6c7069d23
1 b65b3d052
1 fbc32627d
1 4accf443e
1 9a6581390
1 6a01cf902
1 f4e042be3
1 53a748c4b
1 ae71a8e91
1 f03016cad
1 ff20bd164
都是一样的:
[root@mode oldboy]# for n in `seq 30`;do date +%F|md5sum|cut -c 1-9|sort|uniq -c|sort -nk1;done
1 e4b65ddc9
1 e4b65ddc9
1 e4b65ddc9
1 e4b65ddc9
[root@mode oldboy]# for n in `seq 30`;do date +%F|md5sum|cut -c 1-9;done|sort|uniq -c|sort -nk1
30 e4b65ddc9