[Question]
  [
A simple way to scramble a 2x2x2 Rubik's cube is to make a sequence random moves. This is not how official scrambles are done, but can get pretty close to a uniform distribution of all possible scramble states. Due to the way a 2x2 only has two layers, doing one turn on one face is equivalent (without considering the puzzle's orientation in space) to doing the same direction turn on the opposite face. For example, turning the top face clockwise moves all the pieces in relation to each other the same way turning the bottom face clockwise does. So scrambles only need to turn the top (U), right (R), and front (F) faces.
For this challenge, your program must generate a string that represents a sequence of 16 moves. A move is represented by a face, one of the letters `U`, `R`, `F`, followed by a direction: clockwise (empty string or space ), counterclockwise (apostrophe `'`), or 180 degrees (`2`). The turn and direction should be chosen uniformly at random, however two consecutive moves cannot turn the same face, For example a scramble cannot contain `R' R2`. So the first move should have a 1/3 chance for each face, but there should be a 50/50 chance for the chosen face *after the first move*. Moves are separated by a space.
Example scramble:
```
U  F' R2 F' R' F  R  F2 U' F  R2 F  U2 F' U2 F2 
```
  
[Answer]
# [Python 3.8](https://docs.python.org/3.8/), ~~84~~ ~~83~~ 82 bytes
-2 bytes thanks to [dingledooper](https://codegolf.stackexchange.com/users/88546/dingledooper)!
```
import random as R
print(*[(R:=c([*{*"FUR"}-{R}]))+c(" '2")for c in[R.choice]*16])
```
[Try it online!](https://tio.run/##K6gsycjPM7YoKPr/PzO3IL@oRKEoMS8lP1chsVghiKugKDOvREMrWiPIyjZZI1qrWkvJLTRIqVa3Oqg2VlNTO1lDSUHdSEkzLb9IIVkhMy86SC85Iz8zOTVWy9AsVvP/fwA "Python 3.8 (pre-release) – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 19 bytes
```
16Fн…FRUsK… '2âΩð«?
```
[Try it online!](https://tio.run/##yy9OTMpM/f/f0Mztwt5HDcvcgkKLvYG0grrR4UXnVh7ecGi1/f//AA "05AB1E – Try It Online")
```
16F                  # iterate 16 times:
   н                 # get the first character from the value that was last on stack
    …FRU             # push string "FRU"
        sK           # remove the result from н
          … '2       # push string " '2"
              â      # cartesian product of the strings
               Ω     # choose a random string from the list
                ð«   # append a space
                  ?  # print without a trailing newline
```
---
`Ô` - *Connected uniquified a* seems like a promising builtin for this challenge, but the best I could do with it is 22 bytes:
```
…FRU¸Þ€ΩÔ16£ε… '2Ω«}ðý
```
[Try it online!](https://tio.run/##ATAAz/9vc2FiaWX//@KApkZSVcK4w57igqzOqcOUMTbCo8614oCmICcyzqnCq33DsMO9//8 "05AB1E – Try It Online")
```
…FRU¸Þ                 # infinite list ["FRU", "FRU", ... 
     €Ω                # select a random character from each string
       Ô               # remove consecutive duplicates
        16£            # take the first 16 characters
           ε      }    # for each of those:
            … '2Ω«     # append a random char from " '2"
                   ðý  # join the resulting list by spaces
```
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), ~~35~~ ~~29~~ ~~25~~ 19 bytes
```
16(h‛⊍Ṁ⇧$-` '2`Ẋ℅¨…
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=16%28h%E2%80%9B%E2%8A%8D%E1%B9%80%E2%87%A7%24-%60%20%272%60%E1%BA%8A%E2%84%85%C2%A8%E2%80%A6&inputs=&header=&footer=)
Thanks to Lyxal for -6 bytes.
```
16(                 # Repeat 16 times (Automatically closed)
   h                # Take first of previous
    ‛⊍Ṁ⇧            # Push `fru`, uppercased
        $           # Swap top two elements on stack
         -          # Remove (So fru loses the first of previous iteration)
          ` '2`     # Push ` '2`
               Ẋ    # Cartesian product
                ℅   # Random choice
                 ¨… # No idea (Can't find any docs)
```
## My old version, 25 bytes
```
16(‛Ŀ¦⇧'¥≠;℅:£`'2 `℅+⅛)¾Ṅ
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=16%28%E2%80%9B%C4%BF%C2%A6%E2%87%A7%27%C2%A5%E2%89%A0%3B%E2%84%85%3A%C2%A3%60%272%20%60%E2%84%85%2B%E2%85%9B%29%C2%BE%E1%B9%84&inputs=&header=&footer=)
```
16(                   )   # 16 times
   ‛Ŀ¦⇧                   # Push compressed string `fur`, to uppercase
       '  ;               # Filter by...
        ¥≠                # is not equal to register
           ℅              # Random choice
            :£            # Duplicate and push to register
              `'2 `℅      # Random of `'2 `
                    +     # Concatentated
                     ⅛    # Push to global array
                       ¾  # Push global array to stack
                        Ṅ # Join by space
```
I know this is a mess. Also this seems to be the only one that compresses even one of the strings.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 18 bytes
```
Ｆ¹⁶«≔‽⁻FRUωωω‽ 2'→
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z8tv0hBw9BMU6Gai9OxuDgzPU8jKDEvJT9Xwzczr7RYQ8ktKFRJR6FcUxNEWHNxBhRl5pVoIDGhypUUjNSVNEHCvvllqRpWQZnpGSVAbu3///91y3IA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
Ｆ¹⁶«
```
Repeat 16 times.
```
≔‽⁻FRUωω
```
Choose a random turn that wasn't just used.
```
ω
```
Output that turn.
```
‽ 2'
```
Output a random direction.
```
→
```
Except for the last move, leave a space for the next move.
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 50 bytes
```
$
¶FRU¶ 2'
(([FRU])¶.¶.*)\2
$1
16}%@L`.
¶
|' L`..
```
[Try it online!](https://tio.run/##K0otycxLNPz/X4Xr0Da3oNBD2xSM1Lk0NKKB7FjNQ9v0gEhLM8aIS8WQy9CsVtXBJ0EPqJKLq0ZdAcjU@/8fAA "Retina – Try It Online") Explanation:
```
$
¶FRU¶ 2'
```
Append the possible turns and directions.
```
(([FRU])¶.¶.*)\2
$1
```
Remove the turn that was made the last time.
```
%@L`.
```
Pick a random turn and direction from those left.
```
16}`
```
Repeat the above 16 times.
```
¶
```
Join everything together.
```
|' L`..
```
Add spaces between the moves.
[Answer]
# [Factor](https://factorcode.org/), 83 bytes
```
[ [ "UFR"""16 [ over remove random dup , "2 '"random , 32 , ] times ] ""make 2nip ]
```
[Try it online!](https://tio.run/##NY0/C8IwFMS/yvEWl1KwgoPuiouD0ql0iOmThjZ/fElFP30MosvvjoO7uyudvOT2ejofd5hYHM@I/FjYaY4Q5QZvYdXEBWmE9vZmnCqdWPMriYoIwim9gxiXsM8dOlB7uBDRelu8f7JA2Bb9rw1LQAVqsKJfUmHTFPRIxpbXHkTfy8aZgD6nUYxm1BF6ZiX5Aw "Factor – Try It Online")
One of the odd times `make` is shorter than sequence words (or smart combinators like `append-outputs`). Mainly because turning code points into strings is verbose in Factor, but `make`, despite being verbose itself, can do that with ease. Plus, `,` is much shorter than `suffix` or `append`.
## Explanation:
It's a quotation (anonymous function) that takes no input and leaves a string on the data stack as output.
* `[ ... ] ""make` Make a string. Inside the quotation, `,` appends elements to a sequence. The `""` is an exemplar that tells `make` the result should be a string.
* `"UFR"""` Place two strings on the stack. The first, `"UFR"`, indicates which possible faces we can choose. The second, `""`, is the last face we chose, so we don't choose it twice in a row.
* `16 [ ... ] times` Call a quotation 16 times.
* `over remove random` Pick a random face that we didn't pick last time.
* `dup ,` Append it to our sequence without destroying it (since we need to know our last move again).
* `"2 '" random ,` Append a random direction/move to the face.
* `32 ,` Append a space.
* `2nip` Once `make` is done building the string, we still have some junk on the data stack to remove.
[Answer]
# JavaScript (ES6), ~~82 81~~ 79 bytes
```
f=i=>i>>10?"":"FRU"[(i=~~i-Math.random()*~-~!i)%3|0]+" '2"[i*3%3|0]+" "+f(i+64)
```
[Try it online!](https://tio.run/##NcexCsIwEADQXzkPxKQhJbbFQU3c3FwEp@IQ2kZPaiJpcZL8esTB6fEe9m2nLtJrlj70Q85OkzZkzFodELd4PF@wZaRTInmy872M1vfhyXiRZFoQX9YfdRUIqwpbKup/UThGYtPw7EJkHjSoHXjYQ/VTCA5d8FMYh3IMN@YY5/kL "JavaScript (Node.js) – Try It Online")
Or [run a consistency check](https://tio.run/##TY9fT8IwFMXf@RSXJoSWuW4DJMa5@SRvxsTEp7mHOjpWBitpb/yH7KvPzoDap3Nuz7n9dSNehS2M2qPf6JXsujJRSarSNApvCbkmy8cnklGVtK3y7wVW3IhmpXeUTVq/HSo2mn2FuUdgPCWZmszOlnglVd5izjqLAiGBwzEelNrQxukwhgZu4DLsj9Oex@AwADDSutuSstgZVVLn@VY2a6xgmMD8igFWRr8BsepTgjRGG3KKBpkDzTl/jgKO0mLfZb/5UhTSbd9LVKh086/aP7ETWFTnDcGaccd5J9zI0aTQ82c2d2B@e9KO7zh4eNnIAnktPyzt54xbbZD@teu@XejG6q3kW72m9QX8JLM6h@D0eyeiBUwgCkPGUS/Vu1zRKQMPxqMxY3H3DQ) on 500,000 calls
### How?
We start with \$i=0\$. [1]
At each iteration, we add to \$i\$ a random float in \$\left[0,3\right[\$ if \$i=0\$ (3 possible choices) or in \$\left[0,2\right[\$ if \$i\neq 0\$ (only 2 possible choices).
We use \$\lfloor i\bmod 3 \rfloor\$ as the index of the face character and \$\lfloor (3\times i)\bmod 3 \rfloor\$ as the index of the direction character.
After each iteration[1], we update \$i\$ to \$\lfloor i+64 \rfloor\$ in order to:
* get rid of the decimal part whose only purpose was to to choose a direction character
* make sure that we won't pick the same face character twice in a row (because \$64 \bmod3=1\$)
* be able to know that we've processed 16 iterations by testing if \$i\$ is greater than or equal to \$1024\$, because we add at least \$16\times64=1024\$ to \$i\$ (and at most \$16\times65+1=1041\$)
---
*[1] in order to save a few bytes, we actually start with \$i\$ undefined, coerce it to a number at the very beginning of an iteration, and add \$64\$ at the end.*
[Answer]
# [GolfScript](http://www.golfscript.com/golfscript/index.html), 41 bytes
```
16,{;'FRU'[a]-.,rand=:a" '2"3rand=32}%""+
```
[Try It Online!](https://tio.run/##S8/PSStOLsosKPn/39BMp9pa3S0oVD06MVZXT6coMS/F1ipRSUHdSMkYzDE2qlVVUtL@/x8A)
### Explanation
```
16,{;'FRU'[a]-.,rand=:a" 'r"3rand=32}%""+
16,                                        // push the list [0..15]
   {                                       // begin code block
    ;                                      // remove the element already in the list
     'FRU'[a]-                             // remove the previous value of a from the possible choices
                                              (initially, [a] evaluates to an empty list as a is undefined)
              .,rand=                      // push the length of the string, and index the string to a 
                                              random integer in this range
                     :a                    // set a to this value for the next iteration
                       " 'r"               // push " 'r"
                            3rand=         // index the string to a random position
                                  32}      // push the ASCII value for ' ', and end the block
                                     %     // map the block over the list [0..15]
                                      ""+  // convert the resulting list of ASCII values into a string
                                           // the string is output implicitly
```
[Answer]
# [Haskell](https://www.haskell.org/), 114 bytes
```
(' '?16!!)<$>randomRIO(0,9*6^15-1)
_?0=[""]
c?n=[m:d:' ':r|m<-"RUL",m/=c,d<-" '2",r<-m?(n-1)]
import System.Random
```
[Try it online!](https://tio.run/##ZY1BC4IwGEDv@xU6AjW20iAhce4cBIHRySzG1JL85pi7BP32lnTt@B483kNMz3YYXA96NNY7vSbbwqoUqhkBdeziwsALeJL6fpQvCvPz5f4YxmS3TK/JliYRuvGYVRjXSHLFKsiabG4y84ac4vJ8wATWTJJmJi/YYGJyCjxUc1kjSv@3DkSvWFcUTJteWfeR3SDuk6NS6y8 "Haskell – Try It Online") (times out for obvious reasons, you can test it out [here](https://tio.run/##ZY1PC4IwHEDv@xQ6AjW2sg79EefOQRAsOqnFmFqSvzmml6DP3pKuHd@Dx3vI4Vl3nWvB9Hb0zq9hrGEhpK56QA0rXBh4Ad/5fpTOMvvT4nAKY7Kfb65buorQjccsx7hEimuWQ1IlU5HYN6QUi8sRE1gyRaqJvGCNiU0p8FBPZYko/Z86kK1mTZYxY1s9uo9qOnkfHFXGfAE "Haskell – Try It Online") with 8 moves).
The relevant "function" is `(' '?16!!)<$>randomRIO(0,9*6^15-1)`, an `IO String` object "containing" a random sequence of moves.
As always, solving [random](/questions/tagged/random "show questions tagged 'random'") challenges in Haskell is a great idea.
## How?
```
_?0=[""]
c?n=[m:d:' ':r|m<-"RUL",m/=c,d<-" '2",r<-m?(n-1)]
```
(?) is a pure function taking a character `c` and an integer `n` as input and returning the list of all valid sequences of moves of length `n` such that the first move is not `c`.
---
```
(' '?16!!)<$>randomRIO(0,9*6^15-1)
```
`randomRIO(0,9*6^15-1)` generates a random integer in the range `(0,9*6^15-1)`; incidentally, `9*6^15` is exactly the number of valid sequences of length 16. Then with `(' '?16!!)<$>` we use this random integer to index into `' '?16`, which is the list of valid sequences of length 16.
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-S`](https://codegolf.meta.stackexchange.com/a/14339/), ~~20~~ 19 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Would be [17](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LVM&code=R8Y9IiAnMiLvYGaoYGtVKfY&footer=rtR1) if we could output the pairs reversed and in lowercase.
```
GÆ="RUF"kU ï" '2" ö
```
[Test it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LVM&code=R8Y9IlJVRiJrVSDvIiAnMiIg9g) or [run it 100 times](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=R8Y9IlJVRiJrVSDvIiAnMiIg9g&footer=uA&input=MTAwCi1tUg)  
or [verify that the same move isn't used twice in a row over 100 runs](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=R8Y9IlJVRiJrVSDvIiAnMiIg9g&footer=bc7lwCC4&input=MTAwCi1tUg)
```
GÆ="RUF"kU ï" '2" ö
G                        :16
 Æ                       :Map the range [0,G)
  =                      :  Assign to variable U (initially 0)
   "RUF"                 :  String literal
        kU               :  Remove characters in U
           ï" '2"        :  Cartesian product with " '2"
                  ö      :  Random element of resulting array
                         :Implicit output joined with spaces
```
[Answer]
# JavaScript, ~~101~~ ~~99~~ 91 bytes
```
f=(i=s=17,m=Math.random)=>--i?'URF'[s=(s>3?m()*3:s+1+m()*2)%3|0]+" '2"[m()*3|0]+' '+f(i):''
```
[Try it online.](https://tio.run/##y0osSyxOLsosKNHNy09J/f8/zVYj07bY1tBcJ9fWN7EkQ68oMS8lP1fT1k5XN9NePTTITT262Faj2M7YPldDU8vYqljbUBvEMtJUNa4xiNVWUlA3UooGy4G46grq2mkamZpW6ur/k/PzivNzUvVy8tM10jQ0Nf8DAA)
## Explanation
We start with `i` and `s` both set to 17, then each iteration, if subtracting one from `i` yields a positive integer, we get the face character using a simple ternary and add a random direction character and then add a recursive call to `f` with the newly decremented `i`, and otherwise we simply return an empty string.
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 63 61 bytes
```
"$(1..16|%{($l='R','U','F'-ne$l|random)+("'",' ',2|random)})"
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyflvqKdnaGBQo1r9X0lFA8QxA7I1VHJs1YPUddRDgdhNXTcvVSWnpigxLyU/V1NbQ0ldSUddQV3HCCZUq6n0v/Y/AA "PowerShell – Try It Online")
Technically, a 60-byte solution works by using an empty string rather than a space to the second random selection; however, an error is thrown each time the empty element is selected.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 23 bytes
```
“FUR“ '2”Wẋ⁴ŻṖḟ@"X€ɗ\ḊK
```
[Try it online!](https://tio.run/##ATQAy/9qZWxsef//4oCcRlVS4oCcICcy4oCdV@G6i@KBtMW74bmW4bifQCJY4oKsyZdc4biKS/// "Jelly – Try It Online")
A full program that prints a 16-long scramble.
## Explanation
```
“FUR“ '2”               | ["FUR"," '2"]
         W              | Wrap in a further list
          ẋ⁴            | Repeat 16 times
            Ż           | Prepend a zero
                   ɗ\   | Reduce using the following as a dyad, keeping intermediate values:
             Ṗ          | - Remove last item
              ḟ@"       | - Filter out this from the next incoming copy of the list (but because of the Ṗ and ", this will only affect the FUR part)
                 X€     | - Randomly pick a value for each
                     Ḋ  | Remove the first value (the zero)
                      K | Separate with spaces
                        | (Implicitly) print
```
[Answer]
# [J](http://jsoftware.com/), 46 bytes
```
3 :0
,'URF 2'''{~3(,3,~?@3-3:)@|+/\1+?3,15$2
)
```
[Try it online!](https://tio.run/##y/pvqWhlGGumaGWprv4/zdbKWMHKgEtHPTTITcFIXV29us5YQ8dYp87ewVjX2ErToUZbP8ZQ295Yx9BUxYhL87@fk55CSWJyZomCrq6uQrQVHp1ABlCzg46htqGpvYOKkRVXanJGvkKaAtBiAA "J – Try It Online")
Surprisingly verbose.
The only part of this I liked was the code to pick the random faces:
```
3|+/\1+?3,15$2
```
Here we create the 16 element list:
```
3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
```
Then "roll" `?` for each element (so pick randomly among `0 1 2` for the first element, and among `0 1` for the second), then scan sum the result `+/\`, then mod by 3 `3|`.
## tacit version, also 46
```
[:,'URF 2'''{~3(,3,~?@3-3:)@|?@3+/\@,1+15?@$2:
```
But I think the explicit version is easier to read, since if you discount the boilerplate `3 :0` and `)` it is effectively fewer bytes.
[Answer]
# [Raku](https://github.com/nxadm/rakudo-pkg), 54 bytes
```
(<F R U>.roll(*).squish Z~"2' ".comb.roll(*))[^16].put
```
[Try it online!](https://tio.run/##K0gtyjH7/1/Dxk0hSCHUTq8oPydHQ0tTr7iwNLM4QyGqTslIXUFJLzk/NwkmpxkdZ2gWq1dQWvL/PwA "Perl 6 – Try It Online")
* Uses [`squish`](https://docs.raku.org/routine/squish) to get rid of consecutive face repeats
* `Z~` metaoperator zips the two lists, then concatenates the resulting pairs
* `comb` makes light work of the literal space requirement
---
While golfing I found other interesting Raku features that are worth highlighting:
### Alternative, 86 bytes
```
((<F R U>.roll,{{:F<R U>,:R<F U>,:U<F R>}{$_}.roll}…*)Z~"2' ".comb.roll(*))[^16].put
```
[Try it online!](https://tio.run/##K0gtyjH7/19Dw8ZNIUgh1E6vKD8nR6e62srNBsTVsQoCSoDoUJACu9pqlfhasJraRw3LtDSj6pSM1BWU9JLzc5PAwhpamprRcYZmsXoFpSX//wMA "Perl 6 – Try It Online")
* Compact [pair literal](https://docs.raku.org/language/syntax#Pair_literals) syntax within sequence generator to determine valid next cube face
### Alternative, 94 bytes
```
my@m=<F R U>;((@m.roll,{%(@m.map:{$_=>(@m∖$_)}){$_}.roll}…*)Z~"2' ".comb.roll(*))[^16].put
```
[Try it online!](https://tio.run/##K0gtyjH7/z@30iHX1sZNIUgh1M5aQ8MhV68oPydHp1oVxMxNLLCqVom3tQNyHnVMU4nXrNUE8mvBamofNSzT0oyqUzJSV1DSS87PTQILa2hpakbHGZrF6hWUlvz/DwA "Perl 6 – Try It Online")
* Uses [set difference](https://docs.raku.org/language/setbagmix#infix_(-),_infix_%E2%88%96) operator to exclude key from `@m` when creating key-value pairs
[Answer]
# Java, ~~157~~ 151 bytes
```
$->{for(char i=16,c=0,j=3;i-->0;j=2)System.out.format("%c%c ",c="URF".replace(c+"","").charAt(j*=Math.random())," '2".charAt((int)(Math.random()*3)));}
```
*Saved 6 bytes thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210).*
[Try it online!](https://tio.run/##VY9BSwMxFITP3V8RgsWk7obagpc1CyJ468Wil@Lhmd1tE7NJSV4KsuxvX6Powbk8mPnewBi4QGXaj/mc3q1WRFmIkexAOzIWJOvXjwiYz8Xrlgw5ZXsM2h0PbwTCMfKxWJjcJBJqK/rkFGrvxKN3MQ1duH/Nb00v56uqGXsfmDpBIFre3pVKrksjt7WuqmZdG7nh@8@I3SB8QpHRAZDRpVoqQjNLX56fqAjd2YLqmLqhtKSUi@@6B2RmJXeAJxHAtX5gnJeUXG/oX8y0Q87@East57ye5rpY9AKU6s7IXLKW1z/bp2KavwA)
[Answer]
# [Python 3.8 (pre-release)](https://docs.python.org/3.8/), ~~107 106 116 108 105~~ 104 bytes
Basic randoms
-1 bytes to @qwr's space
-1 bytes to @razetime's space
+11 bytes to randomize starting n
-8 bytes by applying new loop method and skipping `' '.join()` and also defining `r` to `randint`
-3 bytes by spliting lines and removing some brackets and rearranging.
-1 byte by changing loop mathod to `exec`.
```
from random import*
r=randint;n=r(0,2)
exec("print('RFU'[(n:=n+r(1,2))%3]+choice('\\' 2'),end=' ');"*16)
```
[Try it online!](https://tio.run/##K6gsycjPM7YoKPr/P60oP1ehKDEvBUhl5hbkF5VocRXZggQy80qs82yLNAx0jDS5UitSkzWUCoqAghrqQW6h6tEaeVa2edpFGoZAaU1V41jt5Iz8zORUDfWYGHUFI3VNndS8FFt1BXVNayUtQzPN//8B "Python 3.8 (pre-release) – Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 83 bytes
```
f=(p='',g=s=>s[0][Math.random()*3|0],a=g`URF`)=>p[47]?p:f(p[0]==a?p:a+g` '2`+' '+p)
```
[Try it online!](https://tio.run/##Dcq9DsIgFEDhV2EDpDb4k5hUb93cXEycSBNu2oKYCgQaJ98dWU6@4bzxi3lMLq5bH6a5FAMsAqWNhQx9VnJQd1xfbUI/hQ/jm8NPDg2C1c/HTXPoozqehmvsDIt1BsBqFFYTuteCEioiLyYkwhzIs7vsaoTgZAw@h2Vul2CZYZyXPw "JavaScript (Node.js) – Try It Online")
* -4 bytes by [Shaggy](https://codegolf.stackexchange.com/users/58974/shaggy)
]