Jump to content

Word Generator


Paulie
 Share

Recommended Posts

This function will take a pattern and generate a random string based on the pattern

Pattern Syntax:

c = consonant

v = vowel

© = letter "c"

(v) = letter "v"

(x,y) = x OR y

Sorry, but this function can NOT generate alphanumeric strings!

;NameGenerator




$TestPattern = "cvxvc"
MsgBox(0,"","A 5-Letter word with an 'x' in the center:"&@CRLF& GenerateName($TestPattern))

$TestPattern= "Paulie (Rocks,Sucks) - He just (c)an't help it... Here is a random (c)onsonant: 'c' and here is a random (v)owel: 'v'"
MsgBox(0,"A Sentance!",GenerateName($TestPattern))


Func GenerateName($Pattern)
    Dim $Consonants[21] = ["B","C","D","F","G","H","J","K","L","M","N","P","Q","R","S","T","V","W","X","Y","Z"]
    Dim $Vowels[5] = ["A","E","I","O","U"]
    If StringInStr($Pattern, "(") Or StringInStr($Pattern, ")") Then
        If CharCount($Pattern, "(") > 9 OR CharCount($Pattern,")") > 9 then SetError(2,"Too Many Groups",-1)
        If CharCount($Pattern, "(") <> CharCount($Pattern,")") Then SetError(3,"Parenthesis",-1)
        $Groups = StringRegExp($Pattern, "\("&".*?"&"\)",3)
        $PlaceHolder= $Pattern
        For $i = 0 to Ubound($Groups)-1
            $PlaceHolder = StringReplace($PlaceHolder, $Groups[$i], $i,1)
        Next
        $chars = StringSplit($PlaceHolder,"")
        $Limit = $chars[0]
        Local $Randomchr[$Limit+1]
        For $i = 1 to $Limit
            If $chars[$i] = "c" then
                $Randomchr[$i] = $Consonants[Random(0,20,1)]
            ElseIf  $chars[$i] = "v" Then
                $Randomchr[$i] = $Vowels[Random(0,4,1)]
            Else
                $RandomChr[$i] = $chars[$i]
            EndIf
        Next
        local $Newstring =""
        For $i = 1 to $Limit
            $Newstring&=$RandomChr[$i]
        Next
        Local $Replacer[Ubound($Groups)]
        For $i = 0 to Ubound($Groups)-1
            If StringInStr($Groups[$i],",") then 
                $Choices = StringSplit(StringTrimLeft(StringTrimRight($Groups[$i],1),1), ",")
                $chr = $Choices[Random(1,$Choices[0],1)]
            Else
                $Chr = StringTrimLeft(StringTrimRight($Groups[$i],1),1)
            EndIf
            $Replacer[$i] = $chr
            $NewString= StringReplace($Newstring, String($i), $Replacer[$i])
        Next
        $Final = $NewString
    Else
        $Chars = StringSplit($Pattern,"")
        $Limit = $Chars[0]
        If $Limit>0 then
            Local $Randomchr[$Limit+1]
            For $i = 1 to $Limit
                If $Chars[$i] = "c" then
                    $Randomchr[$i] = $Consonants[Random(0,20,1)]
                ElseIf  $Chars[$i] = "v" Then
                    $Randomchr[$i] = $Vowels[Random(0,4,1)]
                Else
                    $RandomChr[$i] = $chars[$i]
                EndIf
            Next
            local $Final =""
            For $i = 1 to $Limit
                $Final&=$RandomChr[$i]
            Next
        EndIf
    EndIf
    Return StringUpper(StringLeft($Final,1))&StringLower(StringTrimLeft($Final,1))
EndFunc

Func CharCount($String, $Chr, $CaseSense=0)
    Local $Count = 0
    $Characters = StringSplit($String, "")
    For $i = 1 to $Characters[0]
        If $CaseSense then
            If $Characters[$i] == $Chr then $Count+=1
        Else
            If $Characters[$i] = $Chr then $Count+=1
        EndIf
    Next
    Return $Count
EndFunc
Edited by Paulie
Link to comment
Share on other sites

very cool script :( and it could become the BEST if you could integrate something like regular expressions in it muttley(line in stringregexp) that way u could even have apha numerical strings :)

P.S: i got a Houdini with(cvvcvcv) :P

Edited by TheMadman

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Link to comment
Share on other sites

I'm trying to use this to come up with a cool username that isn't taken everywhere (like "Paulie" is)

Can't come up with a good pattern though... "cv(r,v)(en)vc" has some good results though...

Link to comment
Share on other sites

You've given me something fun to mess with muttley

#Include <Array.au3>
Global $sPattern = "cv(r,v)(en)vc", $azArray[1] = ["Names"], $blah, $blah2
For $i = 1 to 1000
    $blah = GenerateName($sPattern)
    $blah2 = _ArraySearch($azArray, $blah)
    If @error Then
        _ArrayAdd($azArray, $blah)
    EndIf
Next

_ArrayDisplay($azArray)

Gives you (Almost) 1000 different names (Almost because it removes some duplicates).

EDIT: Do you mind if I convert this into a Web-Based Autoit script?

Edited by KentonBomb
Link to comment
Share on other sites

I have it successfully running as a web-based script, albeit it wasn't too difficult the way you wrote it. Just had to "Echo" The names on the page with a bit of formatting. My server is being slow and nit-picky at the moment, so I'll just post a cut-down version. It goes by the "cv(r,v)(en)vc" pattern, which I loved enough to print out a page with 400 words based on that pattern and highlighted the ones I liked.

##WebApp
<html>
<head>
<title>Web-Based Name Generator</title>
</head>
<body>
A few random names: 
<?au3
Global $sPattern = "cv(r,v)(en)vc", $azArray[1] = ["1000"], $blah
$sHtml = "<b>{NAME}</b> &nbsp; &nbsp;"
For $i = 1 to 5
    Echo(StringReplace($sHtml, "{NAME}", GenerateName($sPattern)))
Next

Func GenerateName($Pattern)
    Dim $Consonants[21] = ["B","C","D","F","G","H","J","K","L","M","N","P","Q","R","S","T","V","W","X","Y","Z"]
    Dim $Vowels[5] = ["A","E","I","O","U"]
    If StringInStr($Pattern, "(") Or StringInStr($Pattern, ")") Then
        If CharCount($Pattern, "(") > 9 OR CharCount($Pattern,")") > 9 then SetError(2,"Too Many Groups",-1)
        If CharCount($Pattern, "(") <> CharCount($Pattern,")") Then SetError(3,"Parenthesis",-1)
        $Groups = StringRegExp($Pattern, "\("&".*?"&"\)",3)
        $PlaceHolder= $Pattern
        For $i = 0 to Ubound($Groups)-1
            $PlaceHolder = StringReplace($PlaceHolder, $Groups[$i], $i,1)
        Next
        $chars = StringSplit($PlaceHolder,"")
        $Limit = $chars[0]
        Local $Randomchr[$Limit+1]
        For $i = 1 to $Limit
            If $chars[$i] = "c" then
                $Randomchr[$i] = $Consonants[Random(0,20,1)]
            ElseIf  $chars[$i] = "v" Then
                $Randomchr[$i] = $Vowels[Random(0,4,1)]
            Else
                $RandomChr[$i] = $chars[$i]
            EndIf
        Next
        local $Newstring =""
        For $i = 1 to $Limit
            $Newstring&=$RandomChr[$i]
        Next
        Local $Replacer[Ubound($Groups)]
        For $i = 0 to Ubound($Groups)-1
            If StringInStr($Groups[$i],",") then
                $Choices = StringSplit(StringTrimLeft(StringTrimRight($Groups[$i],1),1), ",")
                $chr = $Choices[Random(1,$Choices[0],1)]
            Else
                $Chr = StringTrimLeft(StringTrimRight($Groups[$i],1),1)
            EndIf
            $Replacer[$i] = $chr
            $NewString= StringReplace($Newstring, String($i), $Replacer[$i])
        Next
        $Final = $NewString
    Else
        $Chars = StringSplit($Pattern,"")
        $Limit = $Chars[0]
        If $Limit>0 then
            Local $Randomchr[$Limit+1]
            For $i = 1 to $Limit
                If $Chars[$i] = "c" then
                    $Randomchr[$i] = $Consonants[Random(0,20,1)]
                ElseIf  $Chars[$i] = "v" Then
                    $Randomchr[$i] = $Vowels[Random(0,4,1)]
                Else
                    $RandomChr[$i] = $chars[$i]
                EndIf
            Next
            local $Final =""
            For $i = 1 to $Limit
                $Final&=$RandomChr[$i]
            Next
        EndIf
    EndIf
    Return StringUpper(StringLeft($Final,1))&StringLower(StringTrimLeft($Final,1))
EndFunc

Func CharCount($String, $Chr, $CaseSense=0)
    StringReplace($String, $Chr, "", 0, $CaseSense)
    Return @extended
EndFunc
?>
 &nbsp;&nbsp; 
Refresh for new names.
 </body>
 </html>

Cut-down link: http://kentonbomb.homelinux.net/codes/web-namegen.auw

Download: http://kentonbomb.homelinux.net/codes/web-namegen.au3

Edited by KentonBomb
Link to comment
Share on other sites

  • 6 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...