bash 快速产生随机数

int32位 posted @ Oct 30, 2013 11:34:09 PM in 未分类 , 2593 阅读
转载请注明: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

Clay Lowe 说:
2025年5月29日 19:15

Below you will understand what is important, the idea provides one of the links with an exciting site: Kissimmee Pest Control

Clay Lowe 说:
2025年5月29日 19:21

On my website you'll see similar texts, write what you think.  Orlando Bed Bug Treatment

Clay Lowe 说:
2025年5月29日 19:23

I read this article. I think You put a lot of effort to create this article. I appreciate your work. Oviedo Termite Treatment

Clay Lowe 说:
2025年5月29日 19:24

I like to recommend exclusively fine plus efficient information and facts, hence notice it: Lakeland Pest Control

Clay Lowe 说:
2025年6月30日 21:39

It is fine, nonetheless evaluate the information and facts around this correct. Scrap Car Removal Port Coquitlam

Clay Lowe 说:
2025年6月30日 21:39

So it is interesting and very good written and see what they think about other people.  Massage Therapy Langley BC

Clay Lowe 说:
2025年7月09日 14:46

I am always searching online for storys that can accommodate me. There is obviously a multiple to understand about this. I feel you made few salubrious points in Attributes moreover. Detain busy, awesome career! Modelagentur Deutschland


登录 *


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