Sign in to follow this  
Followers 0
Newbie2

Can Autoit Randomly Select A Letter?

9 posts in this topic

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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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

10x, guys... :whistle:

Share this post


Link to post
Share on other sites

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


 

Spoiler

shoot_zpsfd329d66.png
dontbelieveeverythingyouthink_zps0e1e900

Madness is the first step to understanding...

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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...

Share this post


Link to post
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
Sign in to follow this  
Followers 0