AutoHotkey Community

It is currently May 27th, 2012, 11:26 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Random text
PostPosted: July 31st, 2009, 9:01 pm 
Offline

Joined: July 8th, 2009, 11:07 am
Posts: 61
Hello!
How can i make a

Code:
random ,TEXT ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 31st, 2009, 9:02 pm 
Before anyone wirtes a code for you...
Why do you want random text?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 31st, 2009, 9:25 pm 
Offline

Joined: July 8th, 2009, 11:07 am
Posts: 61
i want to make a stuff like catchpa


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 31st, 2009, 9:38 pm 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
Code:
; random text into variable
; min lenght 1, mas lenght 10
; only lowercase (asc 97 to 122)

string := ""
Random, text_lenght, 1, 10
Loop, %text_lenght%
{
  Random, asc_code, 1, 26
  asc_code += 96 ; offset (lowercase letters)
  string .= Chr(asc_code)
}

MsgBox % "Variable 'string' contains: " string

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 31st, 2009, 9:46 pm 
Offline

Joined: July 8th, 2009, 11:07 am
Posts: 61
MasterFocus wrote:
Code:
; random text into variable
; min lenght 1, mas lenght 10
; only lowercase (asc 97 to 122)

string := ""
Random, text_lenght, 1, 10
Loop, %text_lenght%
{
  Random, asc_code, 1, 26
  asc_code += 96 ; offset (lowercase letters)
  string .= Chr(asc_code)
}

MsgBox % "Variable 'string' contains: " string


Thank you mate :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 31st, 2009, 9:51 pm 
Offline

Joined: July 8th, 2009, 11:07 am
Posts: 61
asc_code += 96 how can i add numbers?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 31st, 2009, 10:42 pm 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
Created a function for this.

EDIT: see new version below.

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Last edited by MasterFocus on July 31st, 2009, 11:21 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 31st, 2009, 10:53 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
ppeterpp wrote:
asc_code += 96 how can i add numbers?


Chr(Number): Returns the single character corresponding to the ASCII code indicated by Number. If Number is not between 1 and 255 inclusive, an empty string is returned. Common ASCII codes include 9 (tab), 10 (linefeed), 13 (carriage return), 32 (space), 48-57 (the digits 0-9), 65-90 (uppercase A-Z), and 97-122 (lowercase a-z).


IOW, you could define the number range within the random command slightly differently to access the numbers as well as letters. The +=96 line may need to be altered or deleted, though.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 31st, 2009, 11:22 pm 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
EDIT: Solution provided here :)

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2010, 6:44 pm 
Offline

Joined: November 11th, 2008, 11:24 pm
Posts: 55
Location: Ashland
Offtopic: I hate this tiny edit box that doesn't look anything like the resulting post. It's nearly impossible to proof read. I know that's a phpbb thing, just venting, because I'm tired of proofing this post lol

@Antonio

Your "solution" is far too complex for me to understand and since you make it clear in your signature you don't want people just asking for code, via demanding that they attempt to understand I'm going to have to reject it out of hand.

You see? I'm not being "lazy."

Although you may wish I had :P

Here is my question (to anyone willing to answer) via comments in the code below.

The far simpler and more useful code you posted above I have attempted to modify but I don't understand it and have some questions.

Here is my code.

Code:
:*:?r:: ; This is because eventually I want to make it an inline replacement not a msg box. I type question mark r and get the random string.
string := "" ; this is where the results of the loops get placed, yes?
Loop, 10 ; each cycle of the below represents the generation of a character, ok got that, so I want a random string 10 characters long
{
  Random, asc_code, 1, 26 ; Don't fully understand this either. I get random, and the 1 and 26 is a function of length (the alphabet) but I'm not clear on whats going on in relation to the next line.
  asc_code += 48 ; This works but it includes unusable characters, can this be made to fetch only from these ranges? 48-57 (the digits 0-9), 65-90 (uppercase A-Z), and 97-122 (lowercase a-z)
  string .= Chr(asc_code) ; So the contents of asc_code get placed here and it adds the result to the string above?
}

MsgBox % "Variable 'string' contains: " string ; pop up a box who's message is replaced by the things placed in the string by the loop. Also, how could the msg box be made copyable? Or how can I replace this with something like Send? So it turns ?r into the string?

return


Thank you for volunteering your time. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2010, 7:43 pm 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
Quote:
Also, how could the msg box be made copyable?
A MsgBox is automatically copyable. This is true not just for AHK message boxes, but all standard windows message boxes. Try it: Get a MsgBox, press Ctrl-C and then paste it into notepad or somthing -- there is the contents of your message box.

If you just wanted the string in the clipboard so you can paste it, you can use the Clipboard variable:

Code:
MsgBox % "Variable 'string' contains: " string
Clipboard := string ; copy this variable to the clipboard so it can be pasted somewhere else


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2010, 7:47 pm 
Offline

Joined: November 11th, 2008, 11:24 pm
Posts: 55
Location: Ashland
Oh wow, I didn't know that about message boxes, thank you very much, and for the clipboard info as well, I'll attempt to apply it right now. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2010, 7:48 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Code:
:*:?r:: ; This is because eventually I want to make it an inline replacement not a msg box. I type question mark r and get the random string.
string := "" ; this is where the results of the loops get placed, yes?
;--Yes and we want to make sure it starts blank
Loop, 10 ; each cycle of the below represents the generation of a character, ok got that, so I want a random string 10 characters long
;--and you can change that to the number of characters you want, or even 0 for 0 characters
{
  Random, asc_code, 0, 26 + 10 + 26 - 1 ;--This will now include a-z A-Z and 0-9
  If (asc_code <= 9) ;--A number
     asc_code += 48
  else If (asc_code > 9 && asc_code <= 35) ;Capital
     asc_code += 55
  else
      asc_code += 61
  string .= Chr(asc_code) ; So the contents of asc_code get placed here and it adds the result to the string above?
;--Yes.
}

SendInput, % string ;--This will send the new keys inplace of ?r
return
HTH

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2010, 11:21 pm 
Offline

Joined: November 11th, 2008, 11:24 pm
Posts: 55
Location: Ashland
Thank you! That's perfect. And informative! :D :D


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Yahoo [Bot] and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group