在高级 Bash 脚本指南第9.3 章中。$RANDOM:生成随机整数
它说明了如何生成大于特定数字的随机数:
FLOOR=200
number=0 #initialize
while [ "$number" -le $FLOOR ]
do
number=$RANDOM
done
echo "Random number greater than $FLOOR --- $number"
echo
然后评论说:
# Let's examine a simple alternative to the above loop, namely
# let "number = $RANDOM + $FLOOR"
# That would eliminate the while-loop and run faster.
# But, there might be a problem with that. What is it?
我认为它仍然是随机性并且大于$FLOOR,所以我不知道它是什么问题。