#!/bin/bash # Copyright 2005 Daniel Cer (daniel.cer@cs.colorado.edu) # # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/2.5/ or send a letter to # Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, # 94105, USA. PREC_DIG=5 # work-around for lack of easy integer division PREC_MUL=$[10**PREC_DIG] if [ $# -ne 2 ]; then echo -e "Usage:\n\t$0 [int/real] (count)"; exit -1 fi RANDMAX=32767 # as given on the Bash 3.0 man page type=$1; count=$2; if [ "$type" == "int" ]; then for ((i = 0; i < count; i++)); do echo $RANDOM; done elif [ "$type" == "real" ]; then # modulus of RANDOM and RANDMAX+1 is taken to keep the values in the range # [0,1.0) even if the true 'RANDMAX' is ever increased in the future for ((i = 0; i < count; i++)); do result= printf "0.%.${PREC_DIG}d" \ $[((RANDOM%(RANDMAX+1))*PREC_MUL)/(RANDMAX+1)] echo $result done else echo "Invalid type: \"$type\"" fi