morepewpew Posted January 31, 2016 Share Posted January 31, 2016 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 More sharing options...
kaisies Posted January 31, 2016 Share Posted January 31, 2016 (edited) $number = Random (1, 2, 1) Call("test" & $number) But some (myself included) would tell you not to really use this method. It's probably OK for basic scripts though. Edited January 31, 2016 by kaisies Link to comment Share on other sites More sharing options...
JohnOne Posted January 31, 2016 Share Posted January 31, 2016 (edited) 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 January 31, 2016 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 More sharing options...
morepewpew Posted January 31, 2016 Author Share Posted January 31, 2016 I thank both of you Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now