Jump to content

variable Order


 Share

Recommended Posts

  • Moderators

metis,

#include <Array.au3>

HotKeySet("{ESC}", "On_Exit")

Global $aBase[3] = [1, 2, 3]
$aPermute = _ArrayPermute($aBase)

_ArrayDisplay($aPermute)

While 1

    $iIndex = Random(1, $aPermute[0], 1)
    MsgBox(0, "Info", "Starting a new random set")

    $aDisplay = StringSplit($aPermute[$iIndex], "")

    For $i = 1 To $aDisplay[0]
        MsgBox(0, "", $aDisplay[$i])
    Next

WEnd

Func On_Exit()
    Exit
EndFunc

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

Code not work ;/

#include <Array.au3>

HotKeySet("{ESC}", "On_Exit")

Global $aBase[50] = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50"]
$aPermute = _ArrayPermute($aBase)

;~ _ArrayDisplay($aPermute)

While 1

    $iIndex = Random(1, $aPermute[0], 1)
    MsgBox(0, "Info", "Starting a new random set")

    $aDisplay = StringSplit($aPermute[$iIndex], "")
_ArrayDisplay($aDisplay)
_ArrayDisplay($iIndex)
    For $i = 1 To $aDisplay[0]
        MsgBox(0, "", $aDisplay[$i])
    Next

WEnd

Func On_Exit()
    Exit
EndFunc
Link to comment
Share on other sites

  • Moderators

metis,

Please try and be a little more sociable rather than communicating in staccato phrases - it makes everyone more willing to help. ;)

Now "Code not work" is not very informative. :unsure: Next time please give some indication of what error messages you got - it is very helpful when you start debugging.

The reason the code does not work is because the number of permutations of the 50-element array that _ArrayPermute produces results in an array too large for AutoIt to handle. Your initial request only dealt with a 3-element array so the number of permutations was much smaller - of interest it is based on a factorial and there is a big difference between 3! and 50!, as I am sure you know. :D

So we need to go another route - this code redeclares the array on each pass and then (using a pretty standard algorithm) randomly rearranges the elements:

#include <Array.au3>

HotKeySet("{ESC}", "On_Exit")

While 1

    Global $aArray[50] = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25", _
                        "26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50"]

    _ArrayDisplay($aArray)

    For $i = UBound($aArray) - 1 To 1 Step -1
        $j = Random(0, $i, 1)
        $Temp = $aArray[$j]
        $aArray[$j] = $aArray[$i]
        $aArray[$i] = $Temp
    Next

    _ArrayDisplay($aArray)

    MsgBox(0, "Info", "Starting a new random set")

    For $i = 1 To UBound($aArray) - 1
        MsgBox(0, "", $aArray[$i])
    Next

WEnd

Func On_Exit()
    Exit
EndFunc

Is that what you wanted? :>

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

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...