1.RANDOM获取随机数
[root@nginx ~]# echo $RANDOM 30490 ##between 0 to 32767
2.通过openssl产生
[root@nginx ~]# openssl rand -base64 8 2IQNjNQN6Lw= [root@nginx ~]# openssl rand -base64 8|md5sum 40c5768aa647c87c6458bf7d20e47ecc - openssl passwd -salt -1 "you passwd"
3.通过时间获取随机数
[root@nginx ~]# echo $(date +%N) 603982227 [root@nginx ~]# echo $(date +%N) 773256379 [root@nginx ~]# echo $(date +%t%N) 262525931 [root@nginx ~]# echo $(date +%t%N) 486781266
4.通过urandom产生
[root@nginx ~]# head /dev/urandom |cksum 2722703798 2304 [root@nginx ~]# head /dev/urandom |cksum 1047599942 2625 cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16
5.通过UUID产生
[root@nginx ~]# cat /proc/sys/kernel/random/uuid 481523be-a799-4e80-ad91-fca1ca7c39bf [root@nginx ~]# cat /proc/sys/kernel/random/uuid 925ac191-9950-4e94-b360-356898cafbf6 [root@nginx ~]# uuidgen 3214e75b-77d3-40af-a171-205a365562c5 [root@nginx ~]# uuidgen 01ab5b8d-1476-441c-89b2-5e7a03731406
如无特殊说明,文章均为本站原创,转载请注明出处
- 转载请注明来源:获取随机数的几种方法
- 本文永久链接地址:https://www.xionghaier.cn/archives/68.html