Jump to content

Logic Question


Iceburg
 Share

Recommended Posts

I'm trying to figure out a way to do the following, and I can't come up with the logic to code.

I have 12 iterations of a function.

_function(1,1,1)

_fucntion(1,2,1)

_function(1,3,1)

.

.

.

_function(1,12,1)

The script runs once an hour, but I don't always want it to start on (1,1,1), I want it to be random.

So, I was thinking I could do $start_iteration = random(1,12,1) and get a random number and start at that one, but how do I make it go back and make sure its done the 1 through 6, if the starting number is 7?

Link to comment
Share on other sites

  • Moderators

Iceburg,

If you have not yet used the Mod function - here is your chance: ;)

$iStart = Random(0, 11, 1)

For $i = 0 To 11
    ConsoleWrite(Mod($i + $iStart, 12) + 1 & @CRLF)
Next

Any questions? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I have read this question several times and I really don't understand it. If the starting number turns out to be 7, then you run 1 to 7 in order (or) you run 1 to 6 in random order followed by 7 (or) you run 7 followed by 1 to 6 in order (or) you run run 7 followed by 1 to 6 in random order. I also don't know what happens after you have run 1 to 7 (whatever order) nor do I know what happens if the start is not 7. So where's the logic? :geek:

Link to comment
Share on other sites

Says to me, the second parameter needs to go from 1 to a random number, less one.

$start_iteration = random(1,12,1

For $i = 1 To $start_iteration -1
    _function(1,$i,1)
Next
Edited by JohnOne

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

I don't get how Melba's code addresses the question (as it is written).

how do I make it go back and make sure its done the 1 through 6, if the starting number is 7?

The wording may indicate that starting on 7 is forbidden (or at least that the result is not always sequential). This ambiguity casts doubt on all other assumptions one mght make about the question. Melba's code does not go back when the starting number is 7, but instead it keeps going to 12 (no matter).

Edit

In fact I'm quite impressed that Melba was able to decypher this. :whisper:

Edited by czardas
Link to comment
Share on other sites

Hey Melba,

Thanks for the code, mod is definitely the right answer. In my original example, my functions are logically increasing in numbers passed to the function and its easy to replace that number . What if there are 12 different functions that I want to run in that random order? Assign random Mod numbers to each function?

Thanks again for the help here.

Link to comment
Share on other sites

  • Moderators

Iceburg,

I would put the function names into an array and then use the numbers generated as the indices to pull the name and run it using Call:

Global $aFuncs[5] =["Func_1", "Func_2", "Func_3", "Func_4", "Func_5"]

While 1

    $iStart = Random(0, 4, 1)

    For $i = 0 To 4
        $iIndex = Mod($i + $iStart, 5)
        Call($aFuncs[$iIndex])
    Next

    ConsoleWrite(@CRLF)

    If MsgBox(4, "Finished", "Ready for another run?") = 7 Then
        ExitLoop
    EndIf

WEnd

Func Func_1()
    ConsoleWrite("Func 1 called" & @CRLF)
EndFunc

Func Func_2()
    ConsoleWrite("Func 2 called" & @CRLF)
EndFunc

Func Func_3()
    ConsoleWrite("Func 3 called" & @CRLF)
EndFunc

Func Func_4()
    ConsoleWrite("Func 4 called" & @CRLF)
EndFunc

Func Func_5()
    ConsoleWrite("Func 5 called" & @CRLF)
EndFunc

All clear? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Iceburg,

Glad I could help. :)

Incidentally, just for completeness you can also do the loopback like this:

$iStart = Random(1, 12, 1)

For $i = $iStart To 12
    ConsoleWrite($i & @CRLF)
Next

For $i = 1 To $iStart -1
    ConsoleWrite($i & @CRLF)
Next

But using Mod is far more elegant in my opinion. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Iceburg, you might find it interesting to look at It's in the attachment at the end of the linked topic. It gives more examples of using the Mod function, and you could also use _ArrayModalSelect for Melba's code in post No 9 above. (I think I'll rename that UDF to Modulation.au3)

Edited by czardas
Link to comment
Share on other sites

Thanks Czardas, I'll take a look.

I'm still running into issues, here is the code I am trying to run, modeled after the example from Melba23:

Global $aFuncs[5] =["Func_1(3)", "Func_2(4)", "Func_3(5)", "Func_4(8)", "Func_5(9)"]
While 1
$iStart = Random(0, 4, 1)
For $i = 0 To 4
     $iIndex = Mod($i + $iStart, 5)
ConsoleWrite($aFuncs[$iIndex])
     Call($aFuncs[$iIndex])
Next
ConsoleWrite(@CRLF)
If MsgBox(4, "Finished", "Ready for another run?") = 7 Then
     ExitLoop
EndIf
WEnd
Func Func_1($var)
ConsoleWrite("Func 1 called " & $var * 4 & @CRLF)
EndFunc
Func Func_2($var)
ConsoleWrite("Func 2 called " & $var * 4 & @CRLF)
EndFunc
Func Func_3($var)
ConsoleWrite("Func 3 called " & $var * 4 & @CRLF)
EndFunc
Func Func_4($var)
ConsoleWrite("Func 4 called " & $var * 4 & @CRLF)
EndFunc
Func Func_5($var)
ConsoleWrite("Func 5 called " & $var * 4 & @CRLF)
EndFunc

Its breaking cause of the variables in the funtions, but from the console output that I wrote, it appears to call: Func_$iIndex(4), but it doesn't actually ever run it. The console output never shows up.

Edited by Iceburg
Link to comment
Share on other sites

Okay, final answer... doesn't look like the Call accepts args, so I was able to get it working like this:

Global $aFuncs[5] =["Func_1", "Func_2", "Func_3", "Func_4", "Func_5"]
Global $aVars[5] = ["5", "4", "2", "8", "9"]
While 1
    $iStart = Random(0, 4, 1)
;ConsoleWrite($iStart & @CRLF)
  
    local $i = 0
    For $i = 0 To 4
        $iIndex = Mod($i + $iStart, 5)
  ;ConsoleWrite($iIndex)
        Call($aFuncs[$iIndex], $aVars[$iIndex])
    Next
    ConsoleWrite(@CRLF)
    If MsgBox(4, "Finished", "Ready for another run?") = 7 Then
        ExitLoop
    EndIf
WEnd
Func Func_1($var)
    ConsoleWrite("Func 1 called " & $var * 4 & @CRLF)
EndFunc
Func Func_2($var)
    ConsoleWrite("Func 2 called " & $var * 4 & @CRLF)
EndFunc
Func Func_3($var)
    ConsoleWrite("Func 3 called " & $var * 4 & @CRLF)
EndFunc
Func Func_4($var)
    ConsoleWrite("Func 4 called " & $var * 4 & @CRLF)
EndFunc
Func Func_5($var)
    ConsoleWrite("Func 5 called " & $var * 4 & @CRLF)
EndFunc
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...