All pastes #977963 Raw Edit

rand

public shellscript v1 · immutable
#977963 ·published 2008-04-09 05:50 UTC
rendered paste body
#! /bin/shlb=0ub=32768if [ $# -eq 1 ]; then        ub="$1"elif [ $# -eq 2 ]; then        lb="$1"        ub="$2"elif [ $# -ne 0 ]; then        echo "Usage: $0 [[lower_bound] upper_bound]"        echo "  to generate a random number in the range [lower_bound, upper_bound)"        exit 1fi{        echo 'ibase = 16'        printf 'r = '        dd bs=16 count=1 </dev/urandom 2>/dev/null | hexdump -ve '/1 "%02X"'        echo        echo 'ibase = A'        echo "r % ($ub - $lb) + $lb"} | bc 2>/dev/null