Sign in to follow this  
Followers 0
Paulie

Word Generator

20 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



I tested with this pattern

$TestPattern = "cvvcv"
and your function returned very funny name like Zuina,Xaaso,Yaili,Piequ. I like this script. Nice work.


When the words fail... music speaks

Share this post


Link to post
Share on other sites

I testly run it, but I don't know how it can be improved!

muttley :):(

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Love it muttley

simpler charcount function

Func CharCount($String, $Chr, $CaseSense=0)
    StringReplace($String, $Chr, "", 0, $CaseSense)
    Return @extended
EndFunc

[font="Impact"]Never fear, I is here.[/font]

Share this post


Link to post
Share on other sites

Really good job paulie muttley


code

Share this post


Link to post
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...

Share this post


Link to post
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...

I tried that to muttley

Share this post


Link to post
Share on other sites

Konstig is very unique muttley


code

Share this post


Link to post
Share on other sites

Haha, I had "Woef" with: cv(e,n)c

Nice muttley

-AlmarM-


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

Queer to muttley

lol.. I still like the way it sounds...

code

Share this post


Link to post
Share on other sites

Finally used this to come up with a name! :)

I think it has a cool ring to it too...

The name is "Revonik" nobody take it! muttley :(:P

Share this post


Link to post
Share on other sites

I like it. It's more or less a word generator, than a name generator muttley

Qevenol

Mavenov

Morened

Sovener

Wureniz

Sarenuc

Zovenup

Norenat

Movenar

Lovenar

Jirenox


Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

Share this post


Link to post
Share on other sites

I like it. It's more or less a word generator, than a name generator muttley

I realized you were right (Topic title changed)

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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

Lol are you kidding? I'd be honored muttley

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Is something wrong with the script? after i saved the file it's on 0 bytes xD my other scripts are on 30-50 bytes, I got the new 3.0.0 version, Plz help :)

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0