Penisaurus Posted March 11, 2010 Share Posted March 11, 2010 I'm a bit confused with the Random function.I looked over the help file and I get the basics, but I don't want numbers.I've tried this.$Ran = Random(10, 20) Run("Notepad") WinWait("Untitled - Notepad") Send($Ran)Then it gives a random number; in this case: 14.0981190651655If I loop it, it keeps giving me the same number.I'd like to make it so it displays random letters, how would I do that?I'd also like it if it displays random letters, but not the same.I'd like it to send the randoms so when it types it notepad it would type this, or something similar:elekrjelkjlkrfjrlfkrjgwlkjddfjkrlgjrglkrgjrglkejtlkgjtcedkjflrfjr54ltgkrjgtlkgjkjJust whatever gibberish specified.Help? Link to comment Share on other sites More sharing options...
somdcomputerguy Posted March 11, 2010 Share Posted March 11, 2010 (edited) Look over the help file some more. The example there shows how to get letters with the Function Random. Edited March 11, 2010 by snowmaker - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
JohnOne Posted March 11, 2010 Share Posted March 11, 2010 The way to go about this, id to generate a random to number and assign it to a variable ($i). The variable then is used to represent an ascii decimal charactor number for a letter. So the number will have to be withing the range of those letters you want to use. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
z0mgItsJohn Posted March 11, 2010 Share Posted March 11, 2010 I'm guessing this is what your trying to achieve. Local $Alph = StringSplit ('ABCDEFGHIJKLMNOPQRSTUVWXYZ', ''); Puts the letters A-Z in to an array. Local $MaxChar = 10, $Str = '', $Last = ''; $MaxChar = Max letters of gibberish. For $A = 1 To $MaxChar; Start a for loop from 1 to $MaxChar Do $Ran = Random (1, $Alph[0], 1); Produce a random number within range of the $Alph array. Sleep (15); Sleep 15 milli-seconds to insure 0% CPU usage. Until $Ran <> $Last; Make sure the same number is not used twice. $Last = $Ran; Set the current random number to $Last so it is not used twice. Sleep (15); Sleep 15 milli-seconds to insure 0% CPU usage. $Str = $Str & $Alph[$Ran]; Update $Str with the newest letter of gibberish. Next Run ('Notepad'); Run notepad. WinWait ('[CLASS:Notepad]'); Wait for notepad to open. WinActivate ('[CLASS:Notepad]'); Make sure notepad is on top. Send ($Str); Set $Str to notepad. Hope this helps! - John Latest Projects :- New & Improved TCP Chat Link to comment Share on other sites More sharing options...
jchd Posted March 11, 2010 Share Posted March 11, 2010 To avoid repetitive results, use SRandom(@AutoitPID) before using Random(). Not completely foulproof, but better than no seed. @John2010zz, Penisaurus FYI, avoiding duplicate letters in a row gives a _less_ random output than when no such filtering is used. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
ALFJ Posted March 5, 2011 Share Posted March 5, 2011 (edited) I'm guessing this is what your trying to achieve. Local $Alph = StringSplit ('ABCDEFGHIJKLMNOPQRSTUVWXYZ', ''); Local $MaxChar = 10, $Str = '', $Last = ''; $MaxChar = Max letters of gibberish. For $A = 1 To $MaxChar; Start a for loop from 1 to $MaxChar Do $Ran = Random (1, $Alph[0], 1); Produce a random number within range of the $Alph array. Sleep (15); Sleep 15 milli-seconds to insure 0% CPU usage. Until $Ran <> $Last; Make sure the same number is not used twice. $Last = $Ran; Set the current random number to $Last so it is not used twice. Sleep (15); Sleep 15 milli-seconds to insure 0% CPU usage. $Str = $Str & $Alph[$Ran]; Update $Str with the newest letter of gibberish. Next Run ('Notepad'); Run notepad. WinWait ('[CLASS:Notepad]'); Wait for notepad to open. WinActivate ('[CLASS:Notepad]'); Make sure notepad is on top. Send ($Str); Set $Str to notepad. Hope this helps! - John Pretty good one, use it all the time for Random session generation Changed it a lil so you can choose the # of random characters to generate and return 10random characters if the $MaxChar is left blank when called. Func _RandSession($MaxChar=10) Local $Alph = StringSplit ('ABCDEFabcdef123456789', ''); Use these characters in the returned random string ($Str). Local $Str = '', $Last = '' For $A = 1 To $MaxChar; Start a for loop from 1 to $MaxChar Do $Ran = Random (1, $Alph[0], 1); Produce a random number within range of the $Alph array. Sleep (15); Sleep 15 milli-seconds to insure 0% CPU usage. Until $Ran <> $Last; Make sure the same number is not used twice. $Last = $Ran; Set the current random number to $Last so it is not used twice. Sleep (15); Sleep 15 milli-seconds to insure 0% CPU usage. $Str = $Str & $Alph[$Ran]; Update $Str with the newest random character. Next Return $Str EndFunc Example: ConsoleWrite('Random Session using 4 = ' & _RandSession(4) & @CRLF);Returns 4 random characters ConsoleWrite('Random Session using no input = ' & _RandSession() & @CRLF) ;Returns 10 Random Characters Edited March 21, 2011 by ALFJ 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