Jump to content

Random Alpha-numeric character


Recommended Posts

$Number = Chr(Random(48, 57 ,1));--- ASCII Characters 0 to 9
$Upper = Chr(Random(65, 90, 1));--- ASCII Characters A to Z
$Lower = Chr(Random(97, 122, 1));--- ASCII Characters a to z
$X = $Number Or $Upper Or $Lower;--- ASCII Characters 0 to 9, A to Z, or a to z
MsgBox(0, "Random Alpha-Numeric Character", $X)

I want AutoIt to generate a random alpha-numeric character (numbers, upper case letters, lower case letters). However, I am having problem in my 4th line. What is the proper way of doing this?

Thanks! :)

Edited by totoymola
Link to comment
Share on other sites

A quick way; however, the distribution will not be exactly uniform (numbers would appear almost as frequently as letters):

Dim $array[3]
$array[0] = Chr(Random(48, 57 ,1)); ASCII Characters 0 to 9
$array[2] = Chr(Random(65, 90, 1)); ASCII Characters A to Z
$array[1] = Chr(Random(97, 122, 1)); ASCII Characters a to z

$X = $array[Random(0,2,1)]
MsgBox(0, "Random Alpha-Numeric Character", $X)
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

here's something from a couple of years ago, might help, might not

MsgBox(0 , "Random Password", randompass("8"))

Func RandomPass($length)
  Local $letter, $password
   If $length < 9 then
     For $i = 1 To $length
        $letter = Random(33, 126)
        $password = $password & Chr($letter)
     Next
     Return $password
   Else
      Return "Length too long"
   Endif
Endfunc

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • Moderators

$Number = Chr(Random(48, 57 ,1));--- ASCII Characters 0 to 9
$Upper = Chr(Random(65, 90, 1));--- ASCII Characters A to Z
$Lower = Chr(Random(97, 122, 1));--- ASCII Characters a to z
$X = $Number Or $Upper Or $Lower;--- ASCII Characters 0 to 9, A to Z, or a to z
MsgBox(0, "Random Alpha-Numeric Character", $X)

I want AutoIt to generate a random alpha-numeric character (numbers, upper case letters, lower case letters). However, I am having problem in my 4th line. What is the proper way of doing this?

Thanks! :)

Are you trying to do something like:
Dim $RandomChar[5]
$RandomChar[1] = Chr(Random(48, 57, 1)); ASCII Characters 0 to 9
$RandomChar[2] = Chr(Random(65, 90, 1)); ASCII Characters A to Z
$RandomChar[3] = Chr(Random(97, 122, 1)); ASCII Characters a to z
$RandomChar[4] = Random(1, 3, 1)
MsgBox(64, 'Info:', $RandomChar[$RandomChar[4]])oÝ÷ ØêÚºÚ"µÍÌÍÓ[XHÚ[ÛJ

MËJJNÈTÐÒRHÚXÝÈÈBÌÍÕHÚ[ÛJ
KLJJNÈTÐÒRHÚXÝÈHÈÌÍÓÝÙHÚ[ÛJMËLJJNÈTÐÒRHÚXÝÈHÈÌÍÖH  ÌÍÓ[X    [È ÌÍÕ  [È ÌÍÓÝÙÈTÐÒRHÚXÝÈÈKHÈÜHÈÙÐÞ
    ][ÝÔ[ÛH[KS[YXÈÚXÝ][ÝË   ÌÍÖ
?

Edit:

Damn I'm slow!!

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...