Jump to content

# Can Autoit Randomly Select A Letter?

## 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?

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

##### Share on other sites

what about generating int numbers randomly in the range of the ascii values of the letters u want to create and then using the chr function?

##### Share on other sites

Algorithm:

1 - Choose a random integer in the range 1 to 26: \$nLetter

2 - Choose a random integer in the range 0 and 1: \$nCase

3 - Return Chr(\$nLetter + ASC("A") - 1 + \$nCase * (26 + 6))

HTH

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

Edited by GrahamS

GrahamS

##### Share on other sites

Hmm... Good idea. I'll try it.

10x, guys...

##### Share on other sites

don't you know it GrahamS. my internet was out for 5 minutes i come back and boom 5 posts.

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

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

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

## 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
• ### Recently Browsing   0 members

No registered users viewing this page.

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...