bash 快速产生随机数

int32位 posted @ Oct 30, 2013 11:34:09 PM in 未分类 , 2470 阅读
转载请注明:http://krystism.is-programmer.com/若有错误,请多多指正,谢谢!

最简单的方法是读取RANDOM环境变量,比如生成100以内的随机数,可以这样运行:

echo $((RANDOM % 100))

第二种是调用awk中的rand方法,

awk 'BEGIN{print int(rand() * 100)}'

第三种方法是使用shuf命令:

seq 1 99 | shuf -n 1

其他方法类似读取/dev/random 或者 /dev/urandom 则比较复杂。

另外也可以通过调用perl、python、 php等产生随机数,并且都支持单行解释。

转载请注明:http://krystism.is-programmer.com/若有错误,请多多指正,谢谢!
  • 无匹配
  • 无匹配
John 说:
2021年12月16日 14:33

The client must make sure that they discuss the case openly and freely with their celebrity divorce lawyer or any other lawyer that they hire to do the legal work for them. The person just needs to find out the capability of the lawyer and if this is found to be efficient, there is no reason why one could not hire the services of a celebrity divorce lawyer. personal injury attorney nashville


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter