013#猜字游戏
Posted bigtree2pingping
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了013#猜字游戏相关的知识,希望对你有一定的参考价值。
重点:如何生成随机数?
#!/bin/bash
#
random=$(date +%s%N)
max=100
number=$((random%max))
guess=0
guessCount=0
echo "Guess a guess between 1 and $max."
while [ "$guess" -ne $number ]; do
/bin/echo -n "Guess a guess? ";
read guess
if [ "$guess" -gt $number ]; then
echo "too big! input a smaller one: "
elif [ "$guess" -lt $number ]; then
echo "too small! input bigger one: "
fi
guessCount=$(($guessCount+1))
done
echo "Bingo!!! Guessed $number in $guessCount guesses."
exit 0
以上是关于013#猜字游戏的主要内容,如果未能解决你的问题,请参考以下文章