Jump to content
Sign in to follow this  
Canasian

How do you send random string?

Recommended Posts

Canasian

How do you send a random string? I need it to create random game names for diablo 2. I tried using search but found nothing that really helped me ;) So is there a function I don't know of.. or.. do i have to put it in the .ini or what? I think in mm.bot configuration a long time ago i saw in the .ini it had a setup option where you define what characters to use in the random game names it creates.. or you could make it create a game like wonton1 followed by wonton2 wonton3 etc.. So could someone help me out please ^_^? Here is my code.

$UN = IniRead(@ScriptDir & "\Setup.ini","UNPW","Username","Not Found")
$PW = IniRead(@ScriptDir & "\Setup.ini","UNPW","Password","Not Found")
$D2Dir = IniRead(@ScriptDir & "\Setup.ini","D2Dir","Diablo Directory","Not Found")
$Charslot = IniRead(@ScriptDir & "\Setup.ini","Charslot","Slot#","Not Found")
$String = Random()
$Exit = HotKeySet("{ESC}","Stop")

Func Stop()
    Exit
EndFunc


Run($D2Dir)
WinWait("Diablo II")
WinActivate("Diablo II")
WinWaitActive("Diablo II")
Send(50)
WinMove("Diablo II","",0,0)
Sleep(2800)
Send("{TAB}")
Sleep(50)
Send($UN)
Sleep(50)
Send("{TAB}")
Sleep(50)
Send($PW)
Sleep(50)
Send("{ENTER}")

While 1
    Select 
        Case $Charslot = 1
            MouseClick("left",180,160,1)
        ExitLoop
    EndSelect
WEnd

Sleep(200)
Send("{ENTER}")
Sleep(2000)
MouseClick("left",595,485,1)
Sleep(200)
Send ;<== want it to send random string here.

Here's the .ini

[UNPW]
Username = UN
Password = PW

[D2Dir]
Diablo Directory = C:\Program Files\Diablo II\Diablo II.exe -w -ns -skiptobnet

[CharSlot]
Slot# = 1

Share this post


Link to post
Share on other sites
Spiff59

What are the parameters of your random string?

All alpha? Numbers too? Has to start a certain way? Upper or lower case? both? Minimum or maximum length?

Anyway, I might use something like :

MsgBox(1,"",GameName())

Func GameName()
    $Name = ""
    For $x = 1 to 8; length or name (could also be random)
        $y = Random(1, 62, 1)
        Switch $y
            Case 1 to 10
                $Name &= Chr($y + 47); Numbers 0-9
            Case 11 to 36
                $Name &= Chr($y + 54); Letters A-Z
            Case 37 to 62
                $Name &= Chr($y + 60); Letters a-z
        EndSwitch
    Next
    Return $Name
EndFunc

Share this post


Link to post
Share on other sites
Valuater

Maybe...

$UN = IniRead(@ScriptDir & "\Setup.ini", "UNPW", "Username", "Not Found")
$PW = IniRead(@ScriptDir & "\Setup.ini", "UNPW", "Password", "Not Found")
$D2Dir = IniRead(@ScriptDir & "\Setup.ini", "D2Dir", "Diablo Directory", "Not Found")
$Charslot = IniRead(@ScriptDir & "\Setup.ini", "Charslot", "Slot#", "Not Found")
Global $String = StringSplit(IniRead(@ScriptDir & "\Setup.ini", "Random", "String", "Not Found"), ",")


HotKeySet("{F9}", "ShowMe")
HotKeySet("{ESC}", "Stop")

Run($D2Dir)
WinWaitActive("Diablo II")
Send(50)
WinMove("Diablo II", "", 0, 0)
Sleep(2800)
Send("{TAB}")
Sleep(50)
Send($UN)
Sleep(50)
Send("{TAB}")
Sleep(50)
Send($PW)
Sleep(50)
Send("{ENTER}")

MouseClick("left", 180, 160, 1)

While 1
    Sleep(100)
WEnd

Func ShowMe()
    $rnd = Random(1, $String[0], 1)
    Sleep(200)
    Send("{ENTER}")
    Sleep(2000)
    MouseClick("left", 595, 485, 1)
    Sleep(200)
    Send($String[$rnd], 1)
EndFunc   ;==>ShowMe

Func Stop()
    Exit
EndFunc   ;==>Stop

with the ini file....

[Random]

String=Ths,that,the other,etc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Canasian

Thank you spiff59 ^_^ it worked.. but.. i don't understand it much lol i'm a noob xD Is there a way to get it to type only 3 to 15 characters at random? I wish i could understand this lol and read notes.

Func GameName()
    $Name = ""
    For $x = 1 to 15                                  ;  <=== Does x even do anything? lol
        $y = Random(1, 62, 1)
        Switch $y
            Case 1 to 10
                $Name &= Chr($y + 47); Numbers 0-9                     ;<== I don't get how this defines the numbers and
            Case 11 to 36
                $Name &= Chr($y + 54); Letters A-Z               ;<== How this defines letters.. I know it uses ASCII chars but.. don't get that uppercase A-Z in 
            Case 37 to 62
                $Name &= Chr($y + 60); Letters a-z     ;<== ASCII is 65-90 in decimal for uppercase letters right? Or does it not use decimal? 
        EndSwitch
    Next
    Return $Name
EndFunc

And thank you Valuater couldn't really get yours to work the way i wanted it to tho ;) maybe i did something in .ini. It wrote out what was in .ini but didn't scramble it or randomize it.

Edited by Canasian

Share this post


Link to post
Share on other sites
Canasian

Could someone please help me understand how it works?

Share this post


Link to post
Share on other sites
zorphnog

If you are unsure about something, read the documentation on the functions that are used. My guess is that you do not understand how For..To loops or Switch..Case statements work. It's really quite simple stuff if you read the documentation.

For $i = 0 To 9
    ConsoleWrite(GameName() & @LF)
Next

Func GameName()
    $Name = ""
    $iLength = Random(3, 15, 1)      ; Create a random length between 3 and 15 characters
    For $x = 1 to $iLength           ; <=== x determines which character you are currently at in the string
        $y = Random(1, 62, 1)
        Switch $y
            Case 1 to 10             ; y is between 1 and 10
                $Name &= Chr($y + 47); Numbers 0-9     ;<== y + 47 will equal ASCII codes 48 - 57
            Case 11 to 36            ; y is between 11 and 36
                $Name &= Chr($y + 54); Letters A-Z     ;<== y + 54 will equal ASCII codes 65 - 90
            Case 37 to 62            ; y is between 37 and 62
                $Name &= Chr($y + 60); Letters a-z     ;<== y + 60 will equal ASCII codes 97 - 122
        EndSwitch
    Next
    Return $Name
EndFunc

Share this post


Link to post
Share on other sites
Spiff59

Thank you spiff59 ^_^ it worked.. but.. i don't understand it much lol i'm a noob xD Is there a way to get it to type only 3 to 15 characters at random? I wish i could understand this lol and read notes.

Func GameName()
    $Name = ""
    For $x = 1 to 15                                  ;  <=== Does x even do anything? lol
        $y = Random(1, 62, 1)
        Switch $y
            Case 1 to 10
                $Name &= Chr($y + 47); Numbers 0-9                     ;<== I don't get how this defines the numbers and
            Case 11 to 36
                $Name &= Chr($y + 54); Letters A-Z               ;<== How this defines letters.. I know it uses ASCII chars but.. don't get that uppercase A-Z in 
            Case 37 to 62
                $Name &= Chr($y + 60); Letters a-z     ;<== ASCII is 65-90 in decimal for uppercase letters right? Or does it not use decimal? 
        EndSwitch
    Next
    Return $Name
EndFunc
There are always 100 ways to skin a cat. I just chose to generate a single random number between 1 and 62, convert it to one of the 62 ACSII characters I'm allowing, and build the string a byte at a time.

The "x$" is not referenced in this loop, so you could say it doesn't visibly "do" anything. It does hold the for/next loops "counter" variable, that is incremented each time the Next statement is encountered, and then tested each time the loop starts over (at the For statement). Once $x is incremented beyond the upper limit specified in the For statement, the loop is exited and script execution resumes just after the Next statement. More often than not though, the variable controlling the loop is used for something within the loop, like the variable $i is here:

#include<array.au3>
Local $Array[5] = ["John", "Paul", "Fido", "Sue", "Mary"]; 5 elements: 0 through 4
_ArrayDisplay($Array, "Array before loop")
For $i = 0 to 4
    Msgbox(1, "", "Testing array element: " & $i)
    If $Array[$i] = "Fido" Then 
        $Array[$i] = "Spot"
        ExitLoop
    EndIf
Next
Msgbox(1, "", "I found the dog's name in element " & $i & " of the array")
_ArrayDisplay($Array, "Array after loop")

Anyway, we generate a number between 1 and 62 and need to convert that into one of the 62 ASCII characters we're allowing in the output string. We're allowing the ASCII characters 48 through 57 (or hex 30 through 39) which are the numbers "0" though "9", then "A" though "Z" which are ASCII characters 65 though 90 (41 through 5A in hex), and "a" through "z" (97-122 dec, 61-7A hex). We could do this all in either decimal or hex, but given the choice, I'm more comfortable thinking in decimal. If there weren't gaps in the ASCII chart between the groups of characters we wanted to generate, life would have been easy. But to turn our random number, $y, into the desired result, we had to apply different offsets to get to the different groups of characters. We could have assigned the three character groups to $y in any order, I decided to assign the lowest values of $y to the ASCII numbers group ("0"-"9"). So, if $y returned 1 through 10, we add 47 to that, leaving us 48-57. Then we use Chr() to retrieve the ASCII character for that value, and append it to the string we're building ($Name). If our random $y is 11 to 36, we add 54 to it, yeilding 65-90, the uppercase letters, and if $y is 37 to 62, we add 60 to get 97-122, the lowercase alphabet. So, all 62 possibilities for $y, have an offset added to them to make them represent the 62 charcters we're allowing in our string. Make sense (or have I had too much coffee this morning)?

Looking at, playing with, code examples is a great way to learn. And, yes, the help file in AutoIt is very good and chock-full of examples.

Edit: I have had too much coffee. Zorphnog's documented example cuts straight to the point.

Edited by Spiff59

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.