Imports System
Imports System.Collections.Generic
Module Program
Function ReplaceRandomWord(text As String, replacementWords As List(Of String)) As String
Dim words As New List(Of String)(text.Split(" "c))
If words.Count = 0 OrElse replacementWords.Count = 0 Then
Return text ' nothing to do
End If
Dim rnd As New Random()
' Pick random index in the sentence
Dim idx As Integer = rnd.Next(words.Count)
' Pick random replacement word
Dim newWord As String = replacementWords(rnd.Next(replacementWords.Count))
' Replace it
words(idx) = newWord
' Rebuild the string
Return String.Join(" ", words)
End Function
Sub Main()
Dim text As String = "The quick brown fox jumps over the lazy dog"
Dim replacementWords As New List(Of String) From {"c#", "c++", "java", "rust", "python"}
Dim result As String = ReplaceRandomWord(text, replacementWords)
Console.WriteLine(result)
End Sub
End Module
' run:
'
' The quick brown fox java over the lazy dog
'