Search code examples
linuxshellrandom

Random number between range in shell


How I can generate random number between 0-60 in sh (/bin/sh, not bash)? This is a satellite box, there is no $RANDOM variable, and other goods [cksum, od (od -vAn -N4 -tu4 < /dev/urandom)].

I want to randomize a crontab job's time.


Solution

  • 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.