Jump to content

Search the Community

Showing results for tags 'random'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office


  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start



Member Title




Found 25 results

  1. Hi guys I understand that our variables are temporary they are stored in memory while we execute our program but I would like to know if there is a way to make our generated variable to be stored constantly. For example to be able to close our program and when we open it again remember the value we put in the variable. An example would be. Generate a random number after closing our program open it again. and to be able to show the value of the number that we want to store. #include <MsgBoxConstants.au3> Example() Func Example() $number1= Random(1, 6, 1) ;here we generate our first value Global Const $number = $number1 ;We save the value to remember it MsgBox($MB_SYSTEMMODAL, "", "The number generated is : " & $number1) MsgBox($MB_SYSTEMMODAL, "", "The number saved is : " & $number) ; This is the number I want it to save and remember after I close the program and reopen it. EndFunc ;==>Example I hope you understand what I want to do, could you tell me if it is possible to do this? Thanks
  2. Hi guys! I need some help here, is there a way to use Random with While? I need this script to run in between 1 and 4 times but I dont know how to do it, can you please help me? dim $i=1 While $i<=4 Sleep(3000) Send("{LWINDOWN}r{LWINUP}") Sleep(3000) Send("C:\Users\123\Catalogos\tags.txt{ENTER}") Sleep(3000) WinActivate("tags: Bloc de notas","") Sleep(3000) Send("{SHIFTDOWN}{END}{SHIFTUP}{CTRLDOWN}c{CTRLUP}{DEL}{DEL}") Sleep(3000) Send("{CTRLDOWN}g{CTRLUP}{ALTDOWN}{F4}{ALTUP}") Sleep(3000) Send("{CTRLDOWN}v{CTRLUP}{SPACE}") $i=$i+1 WEnd
  3. Hi All, I intend on keeping custom functions/UDFs (works in progress) here; if anyone wants to use any code, feel free. String functions: #AutoIt3Wrapper_AU3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include-once ; #FUNCTION# ==================================================================================================================== ; Name ..........: _DateTimeGet ; Description ...: Returns the date and time formatted for use in sortable filenames, logs, listviews, etc. ; Syntax ........: _DateTimeGet(iType = 1[, $bHumanFormat = False]) ; Parameters ....: $iType - [optional] an integer value. Default is 1. ; 1 - Date and time in file-friendly format; 20190115_113756 ; 2 - Date in file-friendly format; 20190115 ; 3 - Time in file friendly format; 113756 ; $bHumanFormat - [optional] a boolean value. Default is False. ; True - Includes slashes in the date and colons in the time with a space inbetween ; False - No slashes or colons included with an underscore inbetween ; Return values .: Success - String ; Failure - Sets @error to non-zero and returns an empty string ; Author ........: Sam Coates ; =============================================================================================================================== Func _DateTimeGet($iType = 1, $bHumanFormat = False) If $iType < 1 Or $iType > 3 Then Return (SetError(-1, 0, "")) ;; Param1: ;; 1 = Date and time in file friendly format: 20190115_113756 ;; 2 = Date in file friendly format: 20190115 ;; 3 = Time in file friendly format: 113756 ;; Param2: ;; True = Use human-readable format: 15/01/2019 11:37:56 Local $sTime = @HOUR & ":" & @MIN & ":" & @SEC Local $sDate = @MDAY & "/" & @MON & "/" & @YEAR If $iType = 1 Then If $bHumanFormat = False Then $sTime = StringReplace($sTime, ":", "") $sDate = StringReplace($sDate, "/", "") $sDate = StringTrimLeft($sDate, 4) & StringMid($sDate, 3, 2) & StringLeft($sDate, 2) Return ($sDate & "_" & $sTime) Else Return ($sDate & " " & $sTime) EndIf ElseIf $iType = 2 Then If $bHumanFormat = False Then $sDate = StringReplace($sDate, "/", "") $sDate = StringTrimLeft($sDate, 4) & StringMid($sDate, 3, 2) & StringLeft($sDate, 2) EndIf Return ($sDate) ElseIf $iType = 3 Then If $bHumanFormat = False Then $sTime = StringReplace($sTime, "/", "") EndIf Return ($sTime) EndIf EndFunc ;==>_DateTimeGet ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileExtension ; Description ...: Returns a file extension from a filename/FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileExtension($sPath) ; Parameters ....: $sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileExtension($sPath) Return (StringTrimLeft($sPath, StringInStr($sPath, ".", 0, -1))) EndFunc ;==>_FileToFileExtension ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileName ; Description ...: Returns a filename from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileName($sPath[, $bIncludeExtension = True]) ; Parameters ....: $sPath - a string value. ; $bIncludeExtension - [optional] a boolean value. Default is True. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileName($sPath, $bIncludeExtension = True) Local $sReturn = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1)) If $bIncludeExtension = False Then $sReturn = StringLeft($sReturn, StringInStr($sReturn, ".", 0, -1) - 1) Return ($sReturn) EndFunc ;==>_FileToFileName ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFilePath ; Description ...: Returns a folder path from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFilePath($sPath) ; Parameters ....: $sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFilePath($sPath) Return (StringLeft($sPath, StringInStr($sPath, "\", 0, -1) - 1)) EndFunc ;==>_FileToFilePath ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringLeft ; Description ...: Searches for a string inside a string, then removes everything on the right of that string ; Syntax ........: _StringLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1]) ; Parameters ....: $sString - a string value. The string to search inside. ; $sRemove - a string value. The string to search for. ; $iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; $iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1) Return (StringLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) - 1)) EndFunc ;==>_StringLeft ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringRandom ; Description ...: Returns a string of random characters ; Syntax ........: _StringRandom($iAmount[, $iType = 1]) ; Parameters ....: $iAmount - an integer value. Length of returned string ; $iType - [optional] an integer value. Default is 1. ; 1 - Return digits (0-9) ; 2 - Return hexadecimal (0-9, A - F) ; 3 - Return Alphanumeric upper (0-9, A - Z) ; 4 - Return Alphanumeric (0-9, A - Z, a - z) ; 5 - Return Alpha upper (A - Z) ; 6 - Return Alpha (A - Z, a - z) ; Return values .: Success - String ; Failure - Empty string and @error flag as follows: ; @error : 1 - $iAmount is not a positive integer ; 2 - $iType is out of bounds ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringRandom($iAmount, $iType = 1) If $iAmount < 1 Or IsInt($iAmount) = 0 Then Return (SetError(-1, 0, "")) Local $sString = "" Local $iRandomLow = 1, $iRandomHigh = 62 #Tidy_Off Local Static $aCharId[63] = [0, Chr(48), Chr(49), Chr(50), Chr(51), Chr(52), Chr(53), Chr(54), Chr(55), Chr(56), Chr(57), Chr(65), Chr(66), Chr(67), _ Chr(68), Chr(69), Chr(70), Chr(71), Chr(72), Chr(73), Chr(74), Chr(75), Chr(76), Chr(77), Chr(78), Chr(79), Chr(80), _ Chr(81), Chr(82), Chr(83), Chr(84), Chr(85), Chr(86), Chr(87), Chr(88), Chr(89), Chr(90), Chr(97), Chr(98), Chr(99), _ Chr(100), Chr(101), Chr(102), Chr(103), Chr(104), Chr(105), Chr(106), Chr(107), Chr(108), Chr(109), Chr(110), Chr(111), _ Chr(112), Chr(113), Chr(114), Chr(115), Chr(116), Chr(117), Chr(118), Chr(119), Chr(120), Chr(121), Chr(122)] #Tidy_On If $iType = 1 Then ;; digits: 1 - 10 $iRandomHigh = 10 ElseIf $iType = 2 Then ;; hexadecimal: 1 - 16 $iRandomHigh = 16 ElseIf $iType = 3 Then ;; alnumupper: 1 - 36 $iRandomHigh = 36 ElseIf $iType = 4 Then ;; alnum: 1 - 62 $iRandomHigh = 62 ElseIf $iType = 5 Then ;; alphaupper: 11 - 36 $iRandomLow = 11 $iRandomHigh = 36 ElseIf $iType = 6 Then ;; alpha: 11 = 62 $iRandomLow = 11 $iRandomHigh = 62 Else Return (SetError(-2, 0, "")) EndIf For $i = 1 To $iAmount $sString &= $aCharId[Random($iRandomLow, $iRandomHigh, 1)] ;; append string with corresponding random character from ascii array Next Return ($sString) EndFunc ;==>_StringRandom ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringTrimLeft ; Description ...: Searches for a string inside a string, then removes everything on the left of that string ; Syntax ........: _StringTrimLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1]) ; Parameters ....: $sString - a string value. The string to search inside. ; $sRemove - a string value. The string to search for. ; $iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; $iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringTrimLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1) Return (StringTrimLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) + StringLen($sRemove) - 1)) EndFunc ;==>_StringTrimLeft Examples: ConsoleWrite(_StringRandom(100, 6) & @CRLF) ConsoleWrite(_StringTrimLeft("C:\Windows\System32\cmd.exe", "C:\Windows\System32\") & @CRLF) ConsoleWrite(_StringLeft("C:\Windows\System32\cmd.exe", "cmd.exe") & @CRLF) ConsoleWrite(_FileToFileName("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFilePath("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFileExtension("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_StringRandom(6, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(6, 4)& @CRLF)
  4. I need a random string generator which creates 15 letters/numbers. How can I make that?
  5. Hi, I've this script (removed unrelated parts) that generate a set of random chars for a password. It gets launched from a network share by Task Scheduler at a specific time for all PC's, then it relaunches itself from the local drive. Global $LocalToolsDir = @ProgramFilesDir & '\Tools' Start() Func Start() If Not StringInStr(@ScriptFullPath, $LocalToolsDir, 2) Then Exit RunLocaly() Sleep(Random(1, 1800, 1) * 1000) $NewPass = GeneratePass() EndFunc Func GeneratePass() Local $Pass For $i = 1 to 8 $R = Random(0,1.5) If $R > 1 Then $Chr = Random(0,9,1) ElseIf $R < 0.5 Then $Chr = Chr(Random(Asc("A"), Asc("Z"), 1)) Else $Chr = Chr(Random(Asc("a"), Asc("z"), 1)) Endif $Pass &= $Chr Next Return $Pass EndFunc Func RunLocaly() Local $Run = 1, $LocalApp = $LocalToolsDir & '\' & @ScriptName If Not FileExists($LocalApp) Then $Run = FileCopy(@ScriptFullPath, $LocalToolsDir, 1 + 8) If $Run Then Run($LocalApp, $LocalToolsDir) EndFunc The problem is that many PC's ends up with the same password(s). e.g. 10 PC's have (abc123) as a Password, and another 10 have this (def456) Any idea why?
  6. Got a simple question is it possible to have lets say 10 functions and use the random function to randomly pick one of them? If so could anyone please make a tiny example? Tyvm in advance -Dequality
  7. I'm a command-line kind of guy, and I write scripts primarily for myself. Since many websites nowadays require strong passwords, I thought I'd write a simple password generator in AutoIt. I know that AutoIt mavens have written more elaborate pw generators; I offer mine for what it's worth. The compiled script, GenPass.exe, can be downloaded here. See below for Help text and source. Enjoy! Updates: 2017-05-06: Default password changed to variable length of 13-22 characters; argument "1" no longer supported When compiled as GenPW.exe, password is sent directly to the clipboard, no message box unless password generation fails. 2017-05-05: Correction to bypass password generation if argument is ?|H|h 2017-05-03: Added special argument 1 to generate a password of variable length (10-18 characters) including two (2) separator characters 2017-05-02: Added option /S to set a (persistent) randomization seed Help: GenPass.exe|GenPW.exe -- CLD rev. 2017-05-06 Generate a strong password and save it to the Windows clipboard Note: GenPW.exe has the same functionality as GenPass.exe, but sends the generated password directly to the clipboard. No message box is displayed (unless password generation fails). "Strong" means that the password contains random combinations of alphnumeric characters, including at least one uppercase letter (A-N,P-Z), one lowercase letter (a-k,m-z), and one number (0-9). (Generated passwords do not use uppercase O or lowercase l as these characters are easily confused with the numbers 0 and 1.) The length of the password is up to you (see Usage, below), but needless to say, the longer, the stronger. By default, GenPass generates a strong password of between 13 and 22 characters that includes two of the following separator characters: $%&()*+,-./:;@[]_. Alternatively, you can supply a command-line argument in which any number n from 1 to 9 stands for a random sequence of alphanumeric characters of length n, and any other character stands for itself. Thus, you can include fixed words and other characters, such as separators, in the generated password. Spaces in the argument are converted to underscores. Here are some examples: Usage Sample output ----- ------------- GenPass MqU26A*6dS-53r8 GenPass 9 frdhPYDs9 GenPass 58 weoXYHKxDI1uQ GenPass 5.5 UfA6j.43VBB GenPass 3-4-3 0I0-6gq4-njc GenPass 5,3.7 I2FSR,tRZ.fjeIsFy GenPass 3)5(3 UMf)m8513(CBq GenPass 3[haha]3 yLa[haha]P3y GenPass Yes way5 Yes_way1BsUh Seed Option (/S) ---------------- Adding switch /S to the command-line argument causes GenPass to set a seed for the random generation of password characters. A bare /S sets a randomized seed which is written to disk in a file named GenPass.rnd; this seed is used for all subsequent launches of GenPass with the bare /S option. Alternatively, you can specify a seed (range -2^31 to 2^31-1) on the command line with /S [seed]. Here are some examples: GenPass /S GenPass /S 33.3333 GenPass 5,5,5 /S GenPass 5,5,5 /S 33.3333 Note that any subsequent launch of GenPass without the /S option will cause GenPass.rnd to be deleted. Source: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=GenPass.exe #AutoIt3Wrapper_UseUpx=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs GENPASS.AU3 -- AutoIt v3 CLD rev.2017-05-05 ------------------ Generate a strong password and save it to the clipboard >> Command GenPass ? for detailed help << ------------------------------------------------------- #ce #include <Clipboard.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> AutoItSetOption("WinTitleMatchMode", -4) FileInstall ("d:\path\GenPass.htm", @ScriptDir & "\GenPass.htm", $FC_OVERWRITE) ; Template/Seed Local $sTemp = "" Local $bSeed = False, $fSeed=False If $CmdLine[0] Then $sTemp = $CmdLineRaw If $CmdLine[$CmdLine[0]] = "/s" Then $bSeed = True $sTemp = StringTrimRight($sTemp, 2) $sTemp = StringStripWS($sTemp, $STR_STRIPTRAILING) EndIf If $CmdLine[$CmdLine[0] - 1] = "/s" Then $bSeed = True $fSeed = $CmdLine[$CmdLine[0]] $sTemp = StringTrimRight($sTemp, 3 + StringLen($fSeed)) $sTemp = StringStripWS($sTemp, $STR_STRIPTRAILING) EndIf EndIf If Not $sTemp Then $sTemp = "8" If $sTemp = "1" Then $aSeps = StringSplit("#$%&()*+,-./:;@[]_", "") $sTemp = String(Random(3,6,1)) & $aSeps[Random(1,$aSeps[0],1)] & _ String(Random(2,4,1)) & $aSeps[Random(1,$aSeps[0],1)] & _ String(Random(3,6,1)) EndIf $sFn = @ScriptDir&"\GenPass.rnd" If $bSeed Then If Not $fSeed Then If Not FileExists($sFn) Then $fSeed = Random(-1.999^31,1.999^31,0) $h=FileOpen($sFn,2) If $h > -1 Then FileWrite($h,$fSeed) FileClose($h) Else Exit MsgBox($MB_ICONWARNING, @ScriptName, "Error opening " & $sFn) EndIf Else $h=FileOpen($sFn) If $h > -1 Then $fSeed=FileRead($h) FileClose($h) Else Exit MsgBox($MB_ICONWARNING, @ScriptName, "Error opening " & $sFn) EndIf EndIf EndIf SRandom($fSeed) Else If FileExists($sFn) Then FileDelete($sFn) EndIf ; Show help If StringInStr("?Hh", $sTemp) Then If WinExists("[REGEXPTITLE:GenPass.exe:.*]") Then WinActivate("[REGEXPTITLE:GenPass.exe:.*]") Else ShellExecute(@ScriptDir & "\GenPass.htm") EndIf Exit EndIf ; Main $sTemp = StringReplace($sTemp, " ", "_") $iC = 1 While $iC < 10001 $sPW = GenPW($sTemp) If $sPW Then ClipPut($sPW) If Not StringInStr (@ScriptName, "GenPW") Then _ MsgBox($MB_ICONINFORMATION, @ScriptName, $sPW & _ " saved to clipboard" & @CRLF & @CRLF & _ @ScriptName & " ? shows detailed help") Exit Else $iC += 1 EndIf WEnd Exit MsgBox($MB_ICONWARNING, @ScriptName, "Password generation failed!") ;------------------------------- Func GenPw($sTemplate) Local $aIn = StringSplit($sTemplate,"") Local $sOut = "" Local $sABC = _ "0123456789ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz0123456789" Local $aAB = StringSplit($sABC, "") Local $bUC = 0, $bLC = 0, $bNR = 0 For $i = 1 To $aIn[0] If Int($aIn[$i]) Then $iK = $aIn[$i] For $j = 1 To $iK $iR = Random(1, $aAB[0],1) Select Case StringInStr("0123456789", $aAB[$iR]) $bNR = 1 Case StringInStr("ABCDEFGHIJKLMNPQRSTUVWXYZ", _ $aAB[$iR], $STR_CASESENSE) $bUC = 1 Case StringInStr("abcdefghijklmnpqrstuvwxyz", _ $aAB[$iR], $STR_CASESENSE) $bLC = 1 EndSelect $sOut &= $aAB[$iR] Next Else $sOut &= $aIn[$i] EndIf Next If ($bUC And $bLC And $bNR) Then Return $sOut Else Return 0 EndIf EndFunc
  8. Hello everyone ! I've made a little function who return random characters for everyone who would need it.. It's my first function so please have some mercy. And if you have some suggestions.. don't hesitate ! and I made a AutoIt HelpFile that looks like others helpfiles, I hope you'll enjoy ! The function : RandomLetter.au3 The helpfile : RandomLetter.html (in HTML please !) Et pour les anglophobes, voilà l'aide en français : RandomLetter.fr.html (French version of the helpfile) Thanks, hcI
  9. hello everyone, I'm new with AutoIT and just looking for a way to open Firefox with random window size i have tried too many different samples from the web, some how it works but i can't make it works with Firefox MozRpel and ff.au3 installed right now i can open Firefox with this code, but i still can't control the window of Firefox ; open firefox #include <ff.au3> _FFStart() ; open firefox with random size
  10. i have this code running but it just would not start the code: Local $rndSleep = Int (Random(180000,240000,1000)) MsgBox($MB_SYSTEMMODAL, "NaaaNuuu", "This message box will show the sleeptime after closing the tabs, you got " & $rndSleep & " seconds left.", $rndSleep) here is the error it shows me: "C:\Users\numan\Desktop\scipiie.au3" (23) : ==> Variable used without being declared.: MsgBox($MB_SYSTEMMODAL, "NaaaNuuu", "This message box will show the sleeptime after closing the tabs, you got " & $rndSleep & " seconds left.", $rndSleep) MsgBox(^ ERROR
  11. Hello! After watching a whole day of "Journey into cryptography" at Khan Academy, I have got to know the secrets behind some sneaky things! . This is one of em', A PRNG (Pseudo Random Number Generator). Its features (atleast what I believe) are: Simple, short and crappy. Great for beginners who are baffled by the mechanics of random number generation in computers! Support for custom seeds! EIGHT DIGITS OF RANDOMNESS!!! Unlike all other PRNGs, This one is predictable 1000 possible PRNs when using @MSEC as the seed. No option for min or max, the min is 10000000 and the max is 99999999. The Unlicensed . #cs LICENSE This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to <http://unlicense.org/> #ce LICENSE ; #FUNCTION# ==================================================================================================================== ; Name ..........: MiddleSquareRandom ; Description ...: Pseudo-random number generator based on the infamous "Middle Sqaure" method. ; Syntax ........: MiddleSquareRandom([$iSeed = @MSEC]) ; Parameters ....: $iSeed - [optional] A seed for generation of the random number. Default is @MSEC. ; Return values .: A pseudorandom 8 digit integer. ; Author ........: John von Neumann ; Modified ......: Damon Harris (TheDcoder) - Conversion into AutoIt and simplification + further crappification. ; Remarks .......: Fun Fact - The output is based on the $iSeed passed, Same $iSeed = Same pseudo-random number. ; Related .......: Random() ; Link ..........: https://en.wikipedia.org/wiki/Middle-square_method ; Example .......: ConsoleWrite(MiddleSquareRandom() & @CRLF) ; =============================================================================================================================== Func MiddleSquareRandom($iSeed = @MSEC) Local Const $TURNS = 8 Local $sRandomNumber, $sSeed For $iTurn = 1 To $TURNS $iSeed = $iSeed * 2 $sSeed = String($iSeed) $sRandomNumber &= StringMid($sSeed, Ceiling(StringLen($iSeed) / 2), 1) Next Return Int($sRandomNumber) EndFunc Enjoy your numbers, TD . P.S NEVER USE THIS FUNCTION IN A REAL WORLD IMPLEMENTATION OF SOMETHING WHICH USES RANDOM NUMBERS!!! THIS ONE IS VERY UNSUITABLE FOR THAT PURPOSE! READ THE POSTS BELOW FOR MORE INFORMATION.
  12. Hoping for some guidance, I have a string like: $string='vXx2586578£&' How can I go abouts shuffling the contents of the string?
  13. Hello all! In celebration of Rocket League supporting cross platform play with the XBone I wanted to finally create a script to accompany my game winning goals! Currently I have a switch where one button will play this soccer.mp3 while the other cuts the audio in case someone skips the replay during the game. I have a collection of mp3 files that I would like to use from "C:\Rocket" folder and I would like to play a random file from that directory so "C:\Rocket\*.mp3". I am having trouble understanding the random() function and hot to integrate it. Or would I need to create an array before being able to use the random function? Also for note I am trying to use about 20 mp3 files. #include <MsgBoxConstants.au3> Global $g_bPaused = False HotKeySet("{8}", "HotKeyPressed") HotKeySet("{5}", "HotKeyPressed") Func HotKeyPressed() Switch @HotKeyPressed Case "{8}" SoundPlay("") Case "{5}" SoundPlay("C:\Rocket\Soccer.mp3") EndSwitch EndFunc The recordings are newscasters similar to this. Thought that it would have been nice for this to have been in the game to begin with lol Thanks Everyone!
  14. Hello, I am attempting to build a script that will click randomly inside of a box. The box dimensions, number of clicks, and the delay between the clicks is passed to a function. I feel a am very close to finishing this script, but could use a bit of help. I am passing the function four different boxes, two of them to be clicked 18 times, one of them twice and one of them three times. This is repeated four times. The problem I am having is with the first box. It only clicks that box 17 times. It then completes the next three boxes. Once the last box is complete, it does the last click on the first box. I have worked this problem for the past two days now and can not see where I have gone wrong. Any help anyone would be able to provide with this issue would be greatly appreciated. Thank you for your time. The code is below: Opt ("MouseCoordMode", 2) Opt ("MouseClickDelay", 0) HotKeySet ("{ESC}", "Terminate") HotKeySet ("+{F9}", "SelectBox") While 1 Sleep (100) WEnd Func SelectBox () ;Stuff happens here ClickBox () ;Stuff happens here EndFunc ;==>SelectBox Func ClickBox () _MouseClick (431, 271, 477, 311, 18, 50, 100) ;Cick 18 times _MouseClick (317, 272, 385, 306, 18, 50, 100) ;Cick 18 times _MouseClick (683, 267, 749, 306, 2, 50, 100) ;Cick 2 times _MouseClick (504, 267, 568, 306, 3, 50, 100) ;Cick 3 times EndFunc ;==>ClickBox ;$tlx - top left x ;$tly - top left y ;$blx - bottom right x ;$bly - bottom right y ;Numclicks - number of clicks ;$sl1 - sleep low delay ;$sl2 - sleep high delay Func _MouseClick ($tlx, $tly, $brx, $bry, $Numclicks, $sl1, $sl2) Dim $box[4] = [$tlx, $tly, $brx, $bry] For $Count = 1 to $Numclicks MouseMove(Random($box[0], $box[2]), Random($box[1], $box[3]), 0) MouseClick ("left") _Sleep ($sl1, $sl2) Next EndFunc ;==>_MouseClick Func _Sleep ($min, $max) Sleep (Random ($min, $max, 1)) EndFunc ;==>_Sleep Func Terminate() Exit EndFunc ;==>Terminate
  15. ..so I'm testing code for a project where many clients are governed by a master. To test, I generate a random result to emulate real life BUT all the randoms are at unison. Here is an example of what I see: If @Compiled Then Exit MsgBox(0, "Master - RandomTest", "please run this from the editor", 10) #NoTrayIcon #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $iManyTesters = 10 ; how many I run but they all give the same random number ! Global $iRandom = 0 Global $SEC = @SEC If $CmdLine[0] Then AutoItWinSetTitle("RandomTester # " & $CmdLine[1]) While 1 If $SEC <> @SEC Then $SEC = @SEC $iRandom = Random(0, 4, 0) ControlSetText("Master - RandomTest", "", "Edit" & $CmdLine[1], StringRight("00" & $CmdLine[1], 2) & ") " & $iRandom) EndIf Sleep(10) WEnd Exit EndIf Global $n, $Form = GUICreate("Master - RandomTest", 300, 50 + (24 * $iManyTesters) - 46) For $n = 1 To $iManyTesters GUICtrlCreateInput("Input" & $n, 2, 2 + (24 * $n) - 24, 296, 24, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetFont(-1, 15, 400, 0, "Terminal") Next GUISetState(@SW_SHOW) Global $aTesters[$iManyTesters + 1] $aTesters[0] = $iManyTesters $SEC = @SEC Do Sleep(10) Until $SEC <> @SEC For $n = 1 To $iManyTesters $aTesters[$n] = Run('"' & @AutoItExe & '" "' & @ScriptFullPath & '" ' & $n) Next While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete() For $n = 1 To $iManyTesters ProcessClose($aTesters[$n]) Next Exit EndSwitch WEnd is there a better way to generate a random number. One that if generated at the same instance in time, the number would be more random ? Thanks in advance for any pointers to my question.
  16. As stated in other quires, I'm quite new to this, so I'm in need of a little help. All I'm after is a line of code that will do one of the following: Select a file at random from a folder, open it, continue with the rest of the script I've written and then delete that file, then loop. Or, Select the top file (preferred option) and then do the above^ All I'm after is a line that will select a file following one of the above rules. Something like this would be perfect: RandomSelect (C:\Users\User\Desktop\Folder) *.html Deletefile (C:\Users\User\Desktop\Folder) (above file) Thankyou PS: If its not possible for Autoit, would it be possible for any other language?
  17. [Rule] 1. A start would be to get this excel spreadsheet, people called the group, a total divided into two groups: Mary, Sam, Jack 2. Every person eating a fruit, and each times one person can eat the same fruit (or random fruit) 3. Last eaten fruit can not eat 4. so be scheduled 5. If the previous round fruits are finished, the remaining number can pick one randomly 6. If I have more than 100 the number of Name(people), how can I to code it? Picture: 1. The first time Mary eat Apple, Sam can eat Apple(or random),and Jack chose random first to eat. 2. The second They are chose random first to eat. 3. Third They are chose random first to eat. 4. Fourth Sam chose tomato,because the previous round fruits are finished, the remaining number can pick one randomly ,Jack is too. 5. Fifth Sam chose tomato,because the previous round fruits are finished, the remaining number can pick one randomly ,Jack is too. Currently only think of using arrary and for next loop to write it, but I do not know to write Detailing, want to please help me, thank you very much !!!! Thank you!!
  18. I have 35 variables (as shown below) in an array and i want it to randomly select one, and then another and another and another so on, until all 35 are selected but never selecting the same one twice.. this has been my only issue Global $example[35][ex1, ex2, ex3....,] Global $ex1 = MouseClick("Left", x1, y1) Global $ex2 = MouseClick("Left", x1, y1) Global $ex3 = MouseClick("Left", x1, y1) ; ect..... Func Something() Random($example) ;35 Times, cant be same var EndFunc Thanks in advance
  19. So I need some help... basically all I want to do is have Autoit generate a random number between 1 and 3 and then have an if statement that reads the random number... and lets say if it = 3 it will say the number 3 in a msgbox (like this) sleep(500) Random(1,3) If Random = 2 Then MsgBox(0,"","2") EndIf If Random = 1 Then MsgBox(0,"","1") EndIf If Random = 3 Then MsgBox(0,"","3") EndIf can anyone help me? (thanks in advance!)
  20. Hello, i was wondering how i would go about opening a random URL from a predefined list? i am trying to create a small game for the kids, where they have a question and they have to find out the answer (finish the story) from the pages that open...but i need all the pages to be at random, so they need to work out which part comes first, second, third...etc. the code i use to open the URL is and to close the browser: shellexecute("THE URL") If ProcessExists("firefox.exe") Then ProcessClose("firefox.exe") endif is it possible to creaet like a shellexecute("$random") and then add my url's as a ranodm variables? or would it be better to add each script with URL / porcessclose and randomly pick which "url" to open? all help much appreciated MrYonG
  21. Hi everyone I've read all yesterday forums , i think it's me , but i could not find a clue for this : I need to generate large numbers and output into csv format or excel format - Range between 3000000 and 9000000 - Need 5000000 numbers - Numbers should not be in series ( Mixed and Random ) - I would prefere to have a check digits at the end Anyone could help please ? Thank you
  22. PRNG Here's a small PRNG called fliptag. It uses mostly linear math and its state can be completely kept within only 6 "registers" and the implementation is only 27 lines of code long. Verification I ran ent, DIEHARD and the NIST.GOV test suite against it (though I only did all the tests for one fixed seed). I re-ran ent with this, because this implementation has a system-time dependent seed. fliptag has 4 seed parameters, of which 3 are optional. The first one is the genesis seed and determines the starting state. Because this seed is very sensitive to small decimal changes, the current system tickcount (modified) is used in addition to the current system time. (AutoIts MT uses time(NULL)) Here are some sample ent results from the AutoIt test suite, which generates a 1,5 MB file from random bytes: Conclusion 1. Entropy A truly random sequence has an entropy value of 8.0. This is however not achievable by any software PRNG. Both PRNG are on par and have a very respectable entropy value. 2. Compression A dense file (with high entropy) cannot be compressed. Both PRNG achieve perfect scores. 3. Chi² The chi-square test is the most commonly used test for the randomness of data, and is extremely sensitive to errors in pseudorandom sequence generators. The chi-square distribution is calculated for the stream of bytes in the file and expressed as an absolute number and a percentage which indicates how frequently a truly random sequence would exceed the value calculated. We interpret the percentage as the degree to which the sequence tested is suspected of being non-random. If the percentage is greater than 99% or less than 1%, the sequence is almost certainly not random. If the percentage is between 99% and 95% or between 1% and 5%, the sequence is suspect. Percentages between 90% and 95% and 5% and 10% indicate the sequence is “almost suspect”. Both PRNGs achieve very good results. For comparison, Unix' rand() achieves a catastrophic 0.01, a Park & Miller PRNG will achieve roughly 97.5, while a truly - physical - random sequence will result in a Chi² score of about 40.9. 4. Arithmetic mean value Truly random sequences have an arithmetic mean value of exactly 127.5 (0xFF * 0.5). Both PRNG achieve near-perfect scores. 5. Monte Carlo Pi Each successive sequence of six bytes is used as 24 bit X and Y co-ordinates within a square. If the distance of the randomly-generated point is less than the radius of a circle inscribed within the square, the six-byte sequence is considered a “hit”. The percentage of hits can be used to calculate the value of Pi. For very large streams (this approximation converges very slowly), the value will approach the correct value of Pi if the sequence is close to random. Considering that even radioactive decay (true physical randomness) will not achieve better results than both PRNGs. So the scores are almost perfect. 6. Serial Correlation This quantity measures the extent to which each byte in the file depends upon the previous byte. For random sequences, this value (which can be positive or negative) will, of course, be close to zero. A non-random byte stream such as a C program will yield a serial correlation coefficient on the order of 0.5. Wildly predictable data such as uncompressed bitmaps will exhibit serial correlation coefficients approaching 1. Both PRNGs achieve very good results. Download fliptag-3.1.zip
  23. *** EDIT 11/29/14: I made a huge mistake in the original as it only created pairs (i.e. if I get you - you also get me). What I really needed was for each person to get anyone but themselves - but not necessarily create a pair. The issue then became that if there was one person left at the end they could not get themselves. This new version (1.1). Does several things: 1. It creates a unique match for everyone on the list without reciprocal pairs 2. Added: deletion of blank rows before processing 3. Added checking for the word "name" in the first cell to see if headers are included 4. Sample names file included 5. GUI slightly modified *** Its that time of year again. The holidays are upon us. Therefore, I decided to automate the creation a "secret santa" list. These lists are popular around the holidays but usually require at least some manual labor to pair people up. This generator takes the work out of it. Just feed it a list of names via an Excel spreadsheet with the names populated in the first column (no blanks or headers please). It will then generate a new file with the pairings for each name on the list. I even paid for a graphic with usage right that is included in the zip file along with the source and Koda GUI (modified for relative file location of the image). Enjoy. Just the code for those that don't want the whole file: ; Secret Santa Pairing Genertaor ; Use this application to randonmly pair people for secret Santa ; All names must be entered on first col of a spreadhsheet ; no headers - no blank rows ; JFish v 1.1 ;******************************** #include<Excel.au3> #include<Array.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=C:\Users\Jayme\Documents\Code\secret santa\secretSnataGUI2.kxf $Form1 = GUICreate("Secret Santa List Generator v 1.1", 533, 331, 201, 124) GUISetBkColor(0xFFFFFF) $Button1 = GUICtrlCreateButton("Select Excel File With Names", 144, 200, 233, 49) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xA6CAF0) $Pic1 = GUICtrlCreatePic(@ScriptDir&"\400pxSecretSanata.bmp", 64, 8, 404, 172) $Label1 = GUICtrlCreateLabel("Press the above button to select an Excel file containing names in Col A", 16, 264, 507, 24) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Label2 = GUICtrlCreateLabel("The software will randomly produce Secret Santa pairs and display then in a new file", 16, 293, 502, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### func _createList() ; will be used to control the while loop - counts the number of pairs created dim $pairs=0 ; find a an Excel sheet containing names in Col 1 $path=FileOpenDialog("Select File With Secret Santa Names",@ScriptDir,"Excel (*.xl*)" ) If @error Then ; Display the error message. MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.") else ; open excel file from FileOpenDialog GLOBAL $excel=_Excel_Open() Local $oWorkbook = _Excel_BookOpen($excel, $path) ;delete all blank rows in Col A $oWorkbook.ActiveSheet.Columns("A:A").SpecialCells($xlCellTypeBlanks).EntireRow.Delete ; find last non blank row $LastRow = $oWorkbook.ActiveSheet.Range("A1").SpecialCells($xlCellTypeLastCell).Row ;find text in cell A1 to make sure it is not a header Local $aResult = _Excel_RangeRead($oWorkbook, Default, "A1") ;non-comprehensive data check to make sure the number of names is even for pairing and A1 does not contain header if mod($LastRow,2)<>0 or StringInStr($aResult,"name")<>0 then MsgBox("","Data Error","You need to have an even number of names and the file should not contain headers") else $namesArray = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) ; close that workbook _Excel_BookClose($oWorkbook) ; create new 2D array to store the pairings dim $pairingArray[ubound($namesArray)][3] ; populate first row of new array For $a=0 to UBound($pairingArray)-1 $pairingArray[$a][0]=$namesArray[$a] Next ; this starts a loop that will run until everyone has a pairing while $pairs<(UBound($pairingArray)-1) ;this loop looks for a partner for each person on the list sequesntially for $names=0 to UBound($pairingArray)-1 ;does the name have anyone assigned to it? If not then ... if $pairingArray[$names][1]=="" Then ;generate random number local $randomNumber=round(Random(0,ubound($pairingArray)-1),0) ; creates to VARs for name on list and randomly generated name used for comparison $originalName=$pairingArray[$pairs][0] $randomName=$pairingArray[$randomNumber][0] ;checks to ensure that if only one name is left on the list without a partner that you need ;to erase everything and do it again ... this one drove me CRAZY if $pairs==UBound($pairingArray)-2 AND $pairingArray[UBound($pairingArray)-1][1]=="" AND $pairingArray[UBound($pairingArray)-1][2]=="" Then $pairs=0 for $deleteNames=0 to ubound($pairingArray)-1 $pairingArray[$deleteNames][1]="" $pairingArray[$deleteNames][2]="" next ;ConsoleWrite(@crlf&"!!!DEBUG: NEW LOOP TRIGGEED !!!") ExitLoop EndIf ; if the name random name is the same as the person you are matching OR the person you are ; attempting to match has already been assigned then keep trying ... if ($originalName==$randomName) OR ($pairingArray[$randomNumber][2]=="matched") then do $randomNumber=round(Random(0,ubound($pairingArray)-1),0) until ($pairingArray[$pairs][0]<>$pairingArray[$randomNumber][0]) AND ($pairingArray[$randomNumber][2]<>"matched") Endif ; random person looks good so write it to the array $pairingArray[$names][1]=$pairingArray[$randomNumber][0] ; mark that person as matched so we don't pick them again $pairingArray[$randomNumber][2]="matched" ; increment the condition for the outer while loop ; in this case keep going until we have the whole list $pairs+=1 EndIf next WEnd ; paste it to a new results Excel spreadsheet GLOBAL $resultsWorkbook=_Excel_BookNew($excel) _Excel_RangeWrite($resultsWorkbook,$resultsWorkbook.Activesheet,$pairingArray,"A1") EndIf; this one is for the even number check EndIf EndFunc While 1 $nMsg = GUIGetMsg() Switch $nMsg case $Button1 _createList() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd secretsanta1.1.zip
  24. I've been looking around for implementations of noise generators for autoit, but as of yet have had no luck More particularly, I'm looking for an x octave noise generator, but I haven't found any for autoit. Has anyone seen any x octave or perlin noise generators for autoit?
  25. Hey Guys. Happy Christmas and Merry new Year and all that.. I'm currently automating our entire system for end-2-end testing. I have about 12 Complex scripts all joined together in a GUI and it all works. But I want to bring down the amount of lines of code that I used (I Started coding these script without any knowledge of coding/scripting so bear with me..) Currently, I am generating a random number with the following code.. IniWrite(@ScriptDir & "\Iteration.ini ", "Boat Details", "Engine" , Random(111, 999, 1) & Chr(Random(Asc("A"), _ Asc("Z"), 1)) & Chr(Random(Asc("A"), Asc("Z"), 1)) & Random(111, 999, 1) & Chr(Random(Asc("A"), Asc("Z"), 1)) & _ Chr(Random(Asc("A"), Asc("Z"), 1)) & Chr(Random(Asc("A"), Asc("Z"), 1)) & Chr(Random(Asc("A"), Asc("Z"), 1)) & _ Random(111, 999, 1) & Chr(Random(Asc("A"), Asc("Z"), 1)) & Chr(Random(Asc("A"), Asc("Z"), 1))) Please note that the amount of characters is critical for my tests. Now the question, Is there a better way of doing this? Thanx for the assist. Kama
  • Create New...