Random number between range in shell

How about using the nanoseconds of system time?

date +%N

It isn't like you need cryptographically useful numbers here.

Depending on which version of /bin/sh it is, you may be able to do:

$(( date +%N % 60 ))

If it doesn't support the $(()) syntax, but you have dc, you could try:

dc -e `date +%N`' 60 % p'

Without knowing which operating system, version of /bin/sh or what tools are available it is hard to come up with a solution guaranteed to work.


If you have tr, head and /dev/urandom, you can write this:

tr -cd 0-9 </dev/urandom | head -c 3

Then you have to use the remainder operator to put in 0-60 range.


Do you have awk? You can call awk's rand() function. For instance:

awk 'BEGIN { printf("%d\n",rand()*60)  }' < /dev/null