vb Code:
Public Function spin(ByVal str As String) As String
Static RNG As New Random(Now.Millisecond)
Dim matches As Array = Regex.Split(str, "{(.+?)}")
' Discard if no matches
If matches.Length <= 1 Then Return str
Dim match As String = matches(1)
Dim i As Integer = InStr(match, "{")
If i <> 0 Then
match = Mid(match, i + 1)
End If
Dim parts As Array = match.Split("|")
' Random index
i = RNG.Next(0, parts.Length)
' Construct new string
str = Regex.Replace(str, "{" & Regex.Escape(match) & "}", parts(i))
Return spin(str)
End Function