Jump to content

Picking a random letter

Recommended Posts

I know the is a cleaner way to do this.

; pick a random letter A - E

#include <MsgBoxConstants.au3>


Func Example()
    Local $Ran = Random(1, 5, 1)
if $ran = 1 then
    $ran = "A"
if $ran = 2 then
    $ran = "B"
if $ran = 3 then
    $ran = "C"
if $ran = 4 then
    $ran = "D"
if $ran = 5 then
    $ran = "E"
        MsgBox($MB_SYSTEMMODAL, "", "The letter is: " & $Ran)
EndFunc   ;==>Example
Link to comment
Share on other sites

Maybe this way?

#include <MsgBoxConstants.au3>

Global $aChars[26], $i, $sLetter, $iChars
For $i = 0 To 25
    $aChars[$i] = Chr(65 + $i)

$iChars = 10

For $i = 1 To $iChars
    $sLetter &= $aChars[Random(0, UBound($aChars) - 1, 1)]

 MsgBox($MB_SYSTEMMODAL, "", "The letter is: " & $sLetter)

Or much shorter:

#include <MsgBoxConstants.au3>
Global $sLetter, $iChars = 10

For $i = 1 To $iChars
    $sLetter &= Chr(Random(68, 94, 1)) ;A-Z

 MsgBox($MB_SYSTEMMODAL, "", "The letter is: " & $sLetter)



Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites


I know the is a cleaner way to do this.

If you are having trouble following the examples given, just look in the ASCII Characters section in the Help file's Appendix section.

Of importance, is the first two columns, inline with the description column.

Basically, you are working with an incremental number that represents a letter in alphabetical order - Uppercase characters first, then lowercase versions, etc. Using the Chr command, will turn a number into a character i.e. Chr(65) = A, Chr(66) = B, etc. Of course, that number can be stored in a variable.

It is much easier to work with numbers (as a variable), then convert the result to alphanumerical.

P.S. Welcome to the Forum!

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.


What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)


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

  • Recently Browsing   0 members

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