
I'm developing a version of the game Mastermind in bash script. It results to be that when I try to make my non repetitive random code, sometimes, the process takes much more time that the expected.
- Code: Select all
for i in {1..5}
do
if [ $i -eq 1 ]
then
random_num="$(( $RANDOM % 8 + 1 ))"
code=$random_num
else
until [ $full_list -eq 4 ]
do
random_num="$(( $RANDOM % 8 + 1 ))"
for element in $code
do
if [ $element -ne $random_num ]
then
(( full_list++ ))
else
full_list=0
break
fi
done
if [ $full_list -ne 0 ]
then
code="$code $random_num"
fi
done
fi
done
For instance I presume that it is just the "while" which came across with kind of an infinite repeated numbers. OR I did something wrong and can't see it right now.

So in case is the "while"....
Is there a way to limit it? So in case it takes to long to generate the number, starts the loop over?
Does bash allow recursive functions??
Thanks a lot for your time and support!!

