Newbie2 Posted February 17, 2004 Share Posted February 17, 2004 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 Link to comment Share on other sites More sharing options...
dainsleif Posted February 17, 2004 Share Posted February 17, 2004 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? Link to comment Share on other sites More sharing options...
trids Posted February 17, 2004 Share Posted February 17, 2004 Algorithm:1 - Choose a random integer in the range 1 to 26: $nLetter2 - Choose a random integer in the range 0 and 1: $nCase3 - Return Chr($nLetter + ASC("A") - 1 + $nCase * (26 + 6))HTH Link to comment Share on other sites More sharing options...
GrahamS Posted February 17, 2004 Share Posted February 17, 2004 (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 Edited February 17, 2004 by GrahamS GrahamS Link to comment Share on other sites More sharing options...
Newbie2 Posted February 17, 2004 Author Share Posted February 17, 2004 Hmm... Good idea. I'll try it. 10x, guys... Link to comment Share on other sites More sharing options...
Somerset Posted February 17, 2004 Share Posted February 17, 2004 don't you know it GrahamS. my internet was out for 5 minutes i come back and boom 5 posts. Link to comment Share on other sites More sharing options...
Nutster Posted February 19, 2004 Share Posted February 19, 2004 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 NuttallNuttall 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 More sharing options...
GrahamS Posted February 19, 2004 Share Posted February 19, 2004 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 More sharing options...
Nutster Posted February 20, 2004 Share Posted February 20, 2004 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 NuttallNuttall 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now