My existing script can yield "blue,blue,red,red"
but don't want any color to be repeated.
#!/bin/sh
c1="white"
c2='yellow'
c3='orange'
c4='red'
c5='green'
c6='blue'
array=( "$c1" "$c2" "$c3" "$c4" "$c5" "$c6" )
rand0=$RANDOM
rand0=$[ $rand0 % 6 ]
rand1=$RANDOM
rand1=$[ $rand1 % 6 ]
rand2=$RANDOM
rand2=$[ $rand2 % 6 ]
rand3=$RANDOM
rand3=$[ $rand3 % 6 ]
r0=${array[$rand0]}
r1=${array[$rand1]}
r2=${array[$rand2]}
r3=${array[$rand3]}
mastermind=( "$r0" "$r1" "$r2" "$r3" )
How can I filter for duplicates and re-roll them to avoid duplicates?
$[...]
is extremely obsolete (to the point that it hasn't been documented for decades; where did you learn about it?). Use$((...))
instead. – chepner Nov 29 at 2:39