我想根据自定义字符生成一个单词列表。现在我只展示了一个。如何让它显示所有独特的组合?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim num_letters As Integer = 5
Dim num_words As Integer = 1
Dim letters() As Char = "aeiouykzrsdjlxvn".ToCharArray()
Dim rand As New Random()
For i As Integer = 1 To num_words
Dim word As String = ""
For j As Integer = 1 To num_letters
Dim letter_num As Integer = rand.Next(0,
letters.Length - 1)
word &= letters(letter_num)
Next j
Debug.Print(word)
Next i
End Sub
答案 0 :(得分:1)
我创建了这个函数来在辅音和元音之间切换,不要重复它们......试试吧。
Function getName() As String
Dim num_letters As Integer = 5
Dim num_words As Integer = 1
Dim vowel() As Char = "aeiou".ToCharArray()
Dim consonants() As Char = "ykzrsdjlxvn".ToCharArray()
Dim rand As New Random()
Dim word As String = ""
For i As Integer = 1 To num_words
For j As Integer = 1 To num_letters
If j Mod 2 = 0 Then
'CONSONANTS
Dim letter_num As Integer
Do
letter_num = rand.Next(0, consonants.Length - 1)
Loop Until (word.IndexOf(consonants(letter_num)) = -1)
word &= consonants(letter_num)
Else
'VOWEL
Dim letter_num As Integer
Do
letter_num = rand.Next(0, vowel.Length - 1)
Loop Until (word.IndexOf(vowel(letter_num)) = -1)
word &= vowel(letter_num)
End If
Next j
Next i
Return word
End Function
结果示例:esira / edila / oyire / eradi / elijo / olexi / odeka / ovezi / etc ......