I'm making a Rubik's Cube scramble generator, and the turns can't be side by side or else it's useless. I'm trying to stop it from doing the following:Displaying the same string twice, i.e R2 R2Displaying the same kind of string twice, i.e R2 RDisplaying the inverse of the string next to it, i.e R RiHere's the code:    #!/bin/bashturns=( R Ri     L Li    U Ui     D Di    F Fi    B Bi    R2 L2     U2 D2    F2 B2)for ((i=1; i<=$1; i++))do {     turnArray[$i]=${turns[$((RANDOM%18))]}}doneecho ${turnArray[*]}An example of what I want the result to turn out to be:Script yields: D2 B Bi Bi Ri Fi R2 D Li U F2 Ri R2 R2 F2*s around what need to be changed: D2 *B Bi Bi* Ri Fi R2 D Li U F2 Ri *R2 R2* F2(In case you're wondering, the lowercase i in the turn means inverted.)
How to make sure the same string doesn't appear next to itself in an array?
shell script
#!/bin/bashturns=(R Ri L Li U Ui D Di F Fi B Bi R2 L2 U2 D2 F2 B2)declare -A possiblefor i in ${turns[@]}; do        possible[$i]=$(printf %s\n ${turns[@]} | grep -v ${i:0:1})donenext=${turns[*]}for ((i=0; i<$1; i++)); do        j=$(shuf -n 1 -e $next)        turnArray[$i]=$j        next=${possible[$j]}doneecho ${turnArray[*]}Precalculate next possible moves in an assoc array possible.Use shuf to choose next move from arguments.