Jump to content

Can Autoit Randomly Select A Letter?


Newbie2
 Share

Recommended Posts

Hey,

I know I can use 'Random' func in order to randomly choose a number, but can I do the same with letters? :whistle:

All I wanna do is letting the machine to choose a letter for me. It is important tha it chooses capital and NON capital.

Any suggestion?

10x

Link to comment
Share on other sites

Yes it can. Use the Chr function to convert from an ASCII code to a character. The ASCII codes for A to Z are 65 to 90, and a to z are 97 to 122.

So to select an uppercase letter use

Chr(Int(Random(25)) + 65)

Edit: People are too fast around here :whistle:

Edited by GrahamS

GrahamS

Link to comment
Share on other sites

Yes it can. Use the Chr function to convert from an ASCII code to a character. The ASCII codes for A to Z are 65 to 90, and a to z are 97 to 122.

So to select an uppercase letter use

Chr(Int(Random(25)) + 65)
You don't want Z, do you?

Chr(Int(Random(26)) + 65)

Int(Random(26)) returns 26 distinct values (0-25) which we add 65, the first value.

Using Random(25) only give you up to Y.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

You don't want Z, do you?

Chr(Int(Random(26)) + 65)

Int(Random(26)) returns 26 distinct values (0-25) which we add 65, the first value.

Using Random(25) only give you up to Y.

Ah, this goes back to the help file and what is says Random does.

Returns a pseudo-random number between Min and Max (inclusive).

Therefore Random[25] should return a number in the range [0..25] (according to the help file) which is the right range.

Is this function going to be fixed before the formal issue? If not then the help file needs fixed

GrahamS

Link to comment
Share on other sites

Ah, this goes back to the help file and what is says  Random does.

Therefore Random(25) should return a number in the range [0..25] (according to the help file) which is the right range.

Is this function going to be fixed before the formal issue? If not then the help file needs to be fixed.

Unfortunately, those docs were written when integers were part of the variant datatype. See the Random function discussion for more details. With removal of the integer type, the docs became wrong. See the above discussion as to I will be fixing it.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

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...