# Random Function.

## Recommended Posts

How would I exactly go about doing a random function with random amounts?

Example: I want to Send random letters a-z caps and non caps a random amount of times.

"wdwDWd"

"erjtTJGgrgreGERgh"

Something like that?

##### Share on other sites

How would I exactly go about doing a random function with random amounts?

Example: I want to Send random letters a-z caps and non caps a random amount of times.

"wdwDWd"

"erjtTJGgrgreGERgh"

Something like that?

loop

var &= Chr(Random(asc(), asc(), 1))

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

loop

var &= Chr(Random(asc(), asc(), 1))

This is what I currently have.

`ControlSend(\$handle, "", "", Chr(Random(Asc("a"), Asc("z"), 1)))`

That is only sending a random lowercase letter one time. I would like it to send a mix of upper and lowercase randomly with a random amount of times.

"wdwDWd"

"erjtTJGgrgreGERgh"

Something like that?

##### Share on other sites

This is what I currently have.

`ControlSend(\$handle, "", "", Chr(Random(Asc("a"), Asc("z"), 1)))`

That is only sending a random lowercase letter one time. I would like it to send a mix of upper and lowercase randomly with a random amount of times.

"wdwDWd"

"erjtTJGgrgreGERgh"

Something like that?

I gave you the answer. Did you miss the "loop" part before controlsend() and holding the values in var?

Edit:

```Global \$sRanText
For \$iCC = 1 To Random(5, 15, 1)
Switch Random(1, 2, 1)
Case 1
\$sRanText &= Chr(Random(Asc('a'), Asc('z'), 1))
Case 2
\$sRanText &= Chr(Random(Asc('A'), Asc('Z'), 1))
EndSwitch
Next
MsgBox(64, 'Info', \$sRanText)```
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

Doesn't seem to be working. I must be doing something wrong. Is there any other way?

##### Share on other sites

I took your code and made it so it would output for my needs and I still only get one lowercase letter.

```Global \$sRanText
For \$iCC = 1 To Random(5, 15, 1)
Switch Random(1, 2, 1)
Case 1
\$sRanText &= Chr(Random(Asc('a'), Asc('z'), 1))
Case 2
\$sRanText &= Chr(Random(Asc('A'), Asc('Z'), 1))
EndSwitch
Next
ControlSend(\$handle, "", "", \$sRanText)```

##### Share on other sites

I took your code and made it so it would output for my needs and I still only get one lowercase letter.

```Global \$sRanText
For \$iCC = 1 To Random(5, 15, 1)
Switch Random(1, 2, 1)
Case 1
\$sRanText &= Chr(Random(Asc('a'), Asc('z'), 1))
Case 2
\$sRanText &= Chr(Random(Asc('A'), Asc('Z'), 1))
EndSwitch
Next
ControlSend(\$handle, "", "", \$sRanText)```
What happens when you use raw mode? What are you doing anyway?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

I took your code and made it so it would output for my needs and I still only get one lowercase letter.

```Global \$sRanText
For \$iCC = 1 To Random(5, 15, 1)
Switch Random(1, 2, 1)
Case 1
\$sRanText &= Chr(Random(Asc('a'), Asc('z'), 1))
Case 2
\$sRanText &= Chr(Random(Asc('A'), Asc('Z'), 1))
EndSwitch
Next
ControlSend(\$handle, "", "", \$sRanText)```
Try with this you'll see it works.

I prefered put the length in a var as I do'nt know how the compiler do with a function call in the upper limit of the For statement. Does it call the func each time or is smart enough to put it in a register?

```Global \$sRanText,\$length
while 1
\$length=Random(5, 15, 1)
For \$iCC = 1 To \$length
Switch Random(1, 2, 1)
Case 1
\$sRanText &= Chr(Random(Asc('a'), Asc('z'), 1))
Case 2
\$sRanText &= Chr(Random(Asc('A'), Asc('Z'), 1))
EndSwitch
Next
ConsoleWrite(\$sRanText & @CRLF)
\$sRanText=''
Sleep(4000)
Wend```

##### Share on other sites

I prefered put the length in a var as I do'nt know how the compiler do with a function call in the upper limit of the For statement.

[/autoit]

Always one way to find out. Also your loop doesn't address his issue with it only sending lower case (Unless he only tried it once, and that's what the Random chars produced), that's the only thing different other than the var as I presented.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

Always one way to find out. Also your loop doesn't address his issue with it only sending lower case (Unless he only tried it once, and that's what the Random chars produced), that's the only thing different other than the var as I presented.

The issue is that he is using after a send cmd which takes only the first char of the word

Excuse it's not true. I thought about hoykeyset

Otherwise, what do you mean with 'Always one way to find out.'?

Edited by tresa

##### Share on other sites

Try with this you'll see it works.

I prefered put the length in a var as I do'nt know how the compiler do with a function call in the upper limit of the For statement. Does it call the func each time or is smart enough to put it in a register?

```Global \$sRanText,\$length
while 1
\$length=Random(5, 15, 1)
For \$iCC = 1 To \$length
Switch Random(1, 2, 1)
Case 1
\$sRanText &= Chr(Random(Asc('a'), Asc('z'), 1))
Case 2
\$sRanText &= Chr(Random(Asc('A'), Asc('Z'), 1))
EndSwitch
Next
ConsoleWrite(\$sRanText & @CRLF)
\$sRanText=''
Sleep(4000)
Wend```

Even with the idea you have given me, it still only sends one lowercase letter.

##### Share on other sites

does it have to be unique ?

if not , then

```\$var = random()
\$rand = _stringtohex(\$var)
msgbox(0,"",\$rand &"There you go !")```
Edited by WhiteTiger

##### Share on other sites

Even with the idea you have given me, it still only sends one lowercase letter.

to debug put a consolewrite statement just before controlsend to check \$sRanText value

Otherwise, controlsend wait for a window title not an handle?And you do'nt specify a controlName

##### Share on other sites

Why not just use ControlSetText?

Edit:

And @tresa

"One way to find out"

Compile it and find out for yourself if you don't know what it will do.

Edit2:

@rygotype

Maybe look for ControlSendPlus() as well... you still haven't explained what you want this for, all I can think now is how I get these random names on my forum spam

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

Global \$handle = WinGetHandle("classname=GxWindowClassD3d")

##### Share on other sites

Global \$handle = WinGetHandle("classname=GxWindowClassD3d")

Using Opt('WinTitleMatchMode', 4) as well I'm sure?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

AutoItSetOption("WinTitleMatchMode", 4)

##### Share on other sites

AutoItSetOption("WinTitleMatchMode", 4)

Ok, so now we've played the cat and mouse game for 15 posts.

It's time (if you want an actual solution) to do the following:

1. Post a replication script that is similar to what you are currently doing (A working example, don't waste your time with anything else)

2. If there are 3rd party programs involved then provide what they are, links to them if they aren't common, or if it's browser based provide a link they can be interacted with properly.

3. If there are passwords involved, make a dummy account so that the issue can be tested on this end as well.

You asked a question, you received the answer, anything else is a guessing game. If you can't provide the information to us to help you, then you need to figure it out on your own.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

```#include <Misc.au3>

\$string=""
for \$i=1 to Random ( 1,30,1 )
\$string&=_Iif ( random(0,1,1), chr(Random(65,90,1)), chr(Random(97,122,1)) )
Next
send(\$string,1)```

I didnt quite follow some of the posts so i dont know if you already have the answer to your original question if so please ignore this post.

##### Share on other sites

Ive set a limit of 30 characters BTW you can simply change this

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...