I'm trying to generate some quasi random numbers to feed into a monte carlo simulation. I'm using bash. I seem to have hit a syntax error which I've narrowed down to being in this bit of code.
randno4=($RANDOM % 100001)
upper_limit4=$(echo "scale=10; 1*75.3689"|bc)
lower_limit4=$(echo "scale=10; 1*75.1689"|bc)
range4=$(echo "scale=10; $upper_limit4-$lower_limit4"|bc)
t_twall=`echo "scale=10; ${lower_limit4}+${range4}*${randno3}/100001" |bc`
echo "$t_twall"
Does anyone know why I the below output and not a value between 75.3689 and 75.1689 as that is what I would be expecting?
(standard_in) 1: syntax error
randno4=($RANDOM % 100001)is not arithmetic evaluation. That will create arandno4='([0]="25649" [1]="%" [2]="100001")'array. Perhaps you meantrandno4='$(($RANDOM % 100001))'?declare -p randno4. Then tryecho "$randno4"vs.echo "${randno4[1]}".bcbecause of therandno3typo.RANDOM. It is documented as "a random integer between 0 and 32767".mancommand should be pretty much the first Linux command you learn. Here's thebashman page