我需要从一个shell脚本生成的 2000-65000 随机端口号。问题是 $ RANDOM 只是一个16位的数字,所以我坚持!
PORT = $(($ RANDOM%63000 + 2001))将很好地工作,如果不是因为大小的限制。
有没有人有我怎么能做到这一点,一个例子也许从的/ dev / urandom的提取一些东西,得到它的范围之内?
解决方案 SHUF -i 2000-65000 -n 1享受!
的修改的:该范围包含
I need to generate a random port number between 2000-65000 from a shell script. The problem is $RANDOM is only a 16-bit number, so I'm stuck!
PORT=$(($RANDOM%63000+2001)) would work nicely if it wasn't for the size limitation.
Does anyone have an example of how I can do this, maybe by extracting something from /dev/urandom and getting it within a range?
解决方案 shuf -i 2000-65000 -n 1Enjoy!
Edit: The range is inclusive.