Bower Posted December 6, 2008 Share Posted December 6, 2008 In the autoit help file under Random there is an example for a random letter. I don't seem to understand this for some reason... ;Random letter If Random() < 0.5 Then ;Capitals $Letter = Chr(Random(Asc("A"), Asc("Z"), 1)) Else ;Lower case $Letter = Chr(Random(Asc("a"), Asc("z"), 1)) Endif I dont get what the $Letter is doing, tried to look it up in the index and found nothing. Also I dont understand the < 0.5 And confused on the Chr and Asc. I know thats like the hole script but Im new and im just trying to learn ... Like if someone could basically just explain what everything in this script and what it does for the script that would be sweet =) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted December 6, 2008 Moderators Share Posted December 6, 2008 Random without parameters will return a float number .. the number will be less than 1. So the code is saying if Random() returns a number less than 0.5 make capital letters, otherwise, make lower case.http://www.autoitscript.com/autoit3/docs/appendix/ascii.htmChr() converts a decimal number zero to 255 to it's ASCII character value. So Chr(65) would be "A".Asc() converts an ascii character value to a decimal, so Asc("A") would equal 65.Rewritten:Local $s_letter = "" Local $n_number = Random() If $n_number < 0.5 Then $s_letter = Chr(Random(65, 90, 1)); "A - Z", random Else $s_letter = Chr(Random(97, 122, 1)); "a - z", random EndIf MsgBox(64, "Info", "$n_number = " & $n_number & @CRLF & "$s_letter = " & $s_letter) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Bower Posted December 6, 2008 Author Share Posted December 6, 2008 At first I was like o.- what the then I tried the code you said, makes so much more sense. Thanks so much man! Link to comment Share on other sites More sharing options...
Bower Posted December 6, 2008 Author Share Posted December 6, 2008 How do I skip numbers in this? Like i only want Caps and non caps no symbols Local $s_letter = "" $s_letter = Chr(Random(65, 122, 1)); "A - Z", random MsgBox(64, "Info", @CRLF & "$s_letter = " & $s_letter) Link to comment Share on other sites More sharing options...
Bower Posted December 6, 2008 Author Share Posted December 6, 2008 anyone know how? Link to comment Share on other sites More sharing options...
Bower Posted December 6, 2008 Author Share Posted December 6, 2008 I dont want any symbols, its prolly impossible but giving it a try on here. Like just Cap letters and noncaps. Local $s_letter = "" $s_letter = Chr(Random(65, 122, 1)); "A - Z", random MsgBox(64, "Info", @CRLF & "$s_letter = " & $s_letter) Link to comment Share on other sites More sharing options...
ragnarok775 Posted December 6, 2008 Share Posted December 6, 2008 If I understand what your asking this may help... $s_letter = _GenerateLetter() MsgBox(64, "Info", @CRLF & "$s_letter = " & $s_letter) Func _GenerateLetter() Local $Uletter Local $Lletter $Uletter = Chr(Random(65, 90, 1)); "A - Z", random $Lletter = Chr(Random(97, 122, 1)); "a - z", random If Random(0, 1, 1) Then Return $Uletter Else Return $Lletter EndIf EndFunc Uppercase letters are in ASCII 65-90 and Lowercase are in 97-122. the random you had inluded 91-96 which are symbols. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted December 6, 2008 Moderators Share Posted December 6, 2008 Please follow the forum rules on posting. Don't bump posts within 24 hours of your last post, and don't post duplicate topics on the same subject. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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