AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Random Number or Letter

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
sfvipers



Joined: 14 May 2008
Posts: 3

PostPosted: Wed May 14, 2008 7:09 pm    Post subject: Random Number or Letter Reply with quote

How would I get AHK to type 12 Random characters that are either letters a-z or numbers 0-9?
Back to top
View user's profile Send private message Send e-mail
TheIrishThug



Joined: 19 Mar 2006
Posts: 360

PostPosted: Wed May 14, 2008 7:48 pm    Post subject: Reply with quote

You are going to use Loop, Random, and Chr().
Back to top
View user's profile Send private message Visit poster's website AIM Address
sfvipers



Joined: 14 May 2008
Posts: 3

PostPosted: Wed May 14, 2008 7:58 pm    Post subject: Reply with quote

I've figured that much out, but with the random i've only figured how to set a max and min, not multiple max and min since a-z in ASCII is 97-122 and 0-9 is 48-57, also Chr(Random, rand, 97, 122) doesn't work, so I'm not sure how to integrate the Chr() and Random functions
Back to top
View user's profile Send private message Send e-mail
[VxE]



Joined: 07 Oct 2006
Posts: 883

PostPosted: Wed May 14, 2008 8:06 pm    Post subject: Reply with quote

Code:
RChars( number )
{
   list := "1234567890qwertyuiopasdfghjklzxcvbnm"
   Random, ran, 1, % StrLen(list)
   return (number <= 0) ? "" : SubStr( list, ran, 1 ) . RChars( number - 1 )
}

send % RChars( 5 )

_________________
My Home Thread
More Common Answers: 1. It's in the FAQ 2. Ternary ( ? : ) guide 3. Post code with [code][/code] tags
Back to top
View user's profile Send private message
Guest






PostPosted: Wed May 14, 2008 8:08 pm    Post subject: Reply with quote

Try
Code:

Str =
Loop, 12
{
   Random, Rand, 0, 35
   If (Rand < 10)
      Str.= Rand
   Else
      Str.= chr(Rand + 87)
}
Back to top
Guest






PostPosted: Wed May 14, 2008 9:08 pm    Post subject: Reply with quote

RChars( number )
{
list := "1234567890qwertyuiopasdfghjklzxcvbnm"
Random, ran, 1, % StrLen(list)
return (number <= 0) ? "" : SubStr( list, ran, 1 ) . RChars( number - 1 )
}

send % RChars( 5 )

Thanks! Works beautifully! Very Happy
Back to top
Oberon



Joined: 18 Feb 2008
Posts: 458

PostPosted: Wed May 14, 2008 9:21 pm    Post subject: Reply with quote

Here's a slightly modified version:

Code:
rchars(n = 1) {
   Loop, %n% {
      Random, r, 97, 122
      s .= Chr(r)
   }
   Return, s
}

MsgBox % rchars(5)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group