How about something like this:
Sub RandomSplit()
Dim rCell As Range, srcRng As Range, var As Variant
Dim rndLoop As Long, chVar As Variant
Set srcRng = Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
For Each rCell In srcRng.Cells
var = Split(rCell.Offset(, 1).Value, "|")
rndLoop = UBound(var)
chVar = Split(rCell.Value, " ")
For x = 0 To UBound(chVar)
If chVar(x) = "XX" Or chVar(x) = "YY" Then
chVar(x) = Application.Trim(var(Application.RandBetween(0, rndLoop)))
End If
Next x
rCell.Offset(, 2).Value = Join(chVar)
Next rCell
End Sub
It will place its result in column C
Hope this helps