Random number from a range in a Bash Script
Posted
by Jack
on Stack Overflow
See other posts from Stack Overflow
or by Jack
Published on 2010-03-31T20:21:04Z
Indexed on
2010/03/31
20:23 UTC
Read the original article
Hit count: 192
Hi,
I need to generate a random port number between 2000-65000 from a shell script. The problem is $RANDOM is only a 16bit number, so im 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?
Thanks.
© Stack Overflow or respective owner