Jump to content

Function "Random" combined with a function


Recommended Posts

Hello Community,

I'm trying to combine the Random function with a selfwritten function. For example these two functions:

Func test1()
    bla
EndFunc
Func test2()
    blabla
EndFunc

Now I want to use the Random function to start randomly selected function, this was my random (I saved the random number as a variable):

$number = Random (1, 2, 1)

 

My goal is to combine executing one of the two functions, the one which was selected at random.

 

I hope someone could help me :)

 

Link to comment
Share on other sites

Global $funcs[2] = [func1, func2]

$func = $funcs[Random(0, 1, 1)]

$func() ; here the function is called

Func func1()
    MsgBox(0,0,"func1")
EndFunc

Func func2()
    MsgBox(0,0,"func2")
EndFunc

Or simpler still

#include <Array.au3>

Global $funcs[2] = [func1, func2]

$funcs[Random(0, 1, 1)](); here the function is called

Func func1()
    MsgBox(0,0,"func1")
EndFunc

Func func2()
    MsgBox(0,0,"func2")
EndFunc

 

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

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