Jump to content

How to make the script only run 1 out of X amount of times


 Share

Recommended Posts

3 hours ago, Dxnny said:

Say I want a script to run only 1 in 100 times or 1 in 10 times, how would I do that? So it only has a certain chance of running.

Most of my scripts naturally have about that chance of running :)

Code hard, but don’t hard code...

Link to comment
Share on other sites

28 minutes ago, JockoDundee said:

Most of my scripts naturally have about that chance of running :)

I hope your odds are better :lol:.

@Dxnny :

Example : This script starts after the tenth call (see $iStartCount = 10) :

Local $sFilePath = @ScriptDir & "\StartCounter.ini", $iStartCount = 10, $iCounter
If Not FileExists($sFilePath) Then IniWrite($sFilePath, "Counter", "Attempt", 1)
$iCounter = Int(IniRead($sFilePath, "Counter", "Attempt",""))
If $iCounter < $iStartCount Then
    MsgBox(BitOR(4096, 64), "Message", "Attempt = " & String($iCounter)) ; *** just for test
    $iCounter += 1
    Exit IniWrite($sFilePath, "Counter", "Attempt", $iCounter)
EndIf
FileDelete($sFilePath)
MsgBox(BitOR(4096, 64), "Message", "Script starts at attempt = " & String($iCounter)) ; *** just for test

; Your script :
; [...]

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

If Random(1, 10, 1) <> Random(1, 10, 1) Then Exit

; program

(statistically 1 time over 10). You get the surprise as a bonus.

Edited by jchd

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 here
RegExp tutorial: enough to get started
PCRE 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

8 hours ago, Nine said:

After looking at your previous posts, I am wondering what is the application you are trying to automate ?

I’m trying to automate a Discord messaging system, and have some fun with it, only really to learn AutoIt and mess around.

Link to comment
Share on other sites

If Random(1, 10, 1) = Random(1, 10, 1) Then Exit

; program

 

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 here
RegExp tutorial: enough to get started
PCRE 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

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
 Share

  • Recently Browsing   0 members

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