-
Notifications
You must be signed in to change notification settings - Fork 0
/
New-RandomWord.ps1
43 lines (40 loc) · 1.34 KB
/
New-RandomWord.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Ryankrage77's Random Word Generator - Powershell Edition
# Generates random pronouncable strings of a specified length.
$Word = [System.Collections.ArrayList]@()
$Alphabet = "abcdefghijklmnopqrstuvwxyz" -split ""
$Vowels = "aeiou" -split ""
$CurrentLetter = ""
$GenLength = 0
while ($true) {
$StringLength = Read-Host -Prompt "String length"
while ($GenLength -le [int]$StringLength - 1) {
$CurrentLetter = Get-Random $Alphabet
if ($CurrentLetter -in $Vowels) {
if ($GenLength -ge 3) {
if ($Word[($GenLength - 1)] -in $Vowels -and $Word[($GenLength - 2)] -in $Vowels -and $Word[($GenLength - 3)] -in $Vowels) {
#Write-Host "Letter rejected, more than 3 vowels in a row"
continue
}
}
[void]$Word.Add($CurrentLetter)
$GenLength += 1
#Write-Host $Word
} else {
if ($GenLength -ge 2) {
if ($Word[$GenLength - 1] -notin $Vowels -and $Word[$GenLength - 2] -notin $Vowels) {
#Write-Host "Letter rejected, more than 2 consonants in a row"
continue
}
}
[void]$Word.Add($CurrentLetter)
$GenLength += 1
#Write-Host $Word
}
}
$Word[0] = $Word[0].ToUpper()
$FullWord = $Word -join ""
Write-Host "Generated Word: $FullWord"
$GenLength = 0
$Word = [System.Collections.ArrayList]@()
continue
}