| View previous topic :: View next topic |
| Author |
Message |
sfvipers
Joined: 14 May 2008 Posts: 3
|
Posted: Wed May 14, 2008 7:09 pm Post subject: Random Number or Letter |
|
|
| How would I get AHK to type 12 Random characters that are either letters a-z or numbers 0-9? |
|
| Back to top |
|
 |
TheIrishThug
Joined: 19 Mar 2006 Posts: 360
|
Posted: Wed May 14, 2008 7:48 pm Post subject: |
|
|
| You are going to use Loop, Random, and Chr(). |
|
| Back to top |
|
 |
sfvipers
Joined: 14 May 2008 Posts: 3
|
Posted: Wed May 14, 2008 7:58 pm Post subject: |
|
|
| 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 |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 883
|
Posted: Wed May 14, 2008 8:06 pm Post subject: |
|
|
| 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 |
|
 |
Guest
|
Posted: Wed May 14, 2008 8:08 pm Post subject: |
|
|
Try
| Code: |
Str =
Loop, 12
{
Random, Rand, 0, 35
If (Rand < 10)
Str.= Rand
Else
Str.= chr(Rand + 87)
} |
|
|
| Back to top |
|
 |
Guest
|
Posted: Wed May 14, 2008 9:08 pm Post subject: |
|
|
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!  |
|
| Back to top |
|
 |
Oberon
Joined: 18 Feb 2008 Posts: 458
|
Posted: Wed May 14, 2008 9:21 pm Post subject: |
|
|
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 |
|
 |
|