Sign in to follow this  
Followers 0
kw_rock

Random function?

9 posts in this topic

Ok... I have multiple different functions that do the same thing just in a different way, and I want to randomly choose them

They are Hello1, Hello2, Hello3, Hello4, etc all the way to 10

And I want to put them into a While statement to always run...

While 1

Hello(Random(1, 10, 1))

WEnd

That doesn't work, is there any other way?

I also tried to declare a variable...

$Hello = Hello(Random(1, 10))

then do While 1

(($Hello))

WEnd

But that says error parsing function.

Anyone have a way I could do this? Thanks!

Share this post


Link to post
Share on other sites



While 1
     Hello(Random(1,10))
WEnd

Func Hello($Number)
     Select
          Case $Number = 1
               ;Do func #1 code here
          Case $Number = 2
               ;Do func #2 code here
          Case $Number = 3
               ;Do func #3 code here
          Case $Number = 4
               ;Do func #4 code here
          Case $Number = 5
               ;Do func #5 code here
          Case $Number = 6
               ;Do func #6 code here
          Case $Number = 7
               ;Do func #7 code here
          Case $Number = 8
               ;Do func #8 code here
          Case $Number = 9
               ;Do func #9 code here
          Case $Number = 10
               ;Do func #10 code here
     EndSelect
EndFunc

Hope that helps.


Ha, I haven't been on these forums since... 2006, almost. Behold, my legacy signature:My AutoIt idol is Valuater. You know you love him, too.My Stuff: D&D AGoT Tools Suite

Share this post


Link to post
Share on other sites

Hmmm... I did that, but it doesn't do anything.

Doesn't give error message, but it doesn't work.

I just had each send a number, but it didn't do anything.

Share this post


Link to post
Share on other sites

Wow, sorry, a stupid error. The Random() gives something like 2.12331243817, but it needs to be rounded. I just changed the Random() to Random(1,10,1), and it works. Tested.

While 1
     Hello(Random(1,10,1))
WEnd

Func Hello($Number)
     Select
          Case $Number = 1
               ;Do func #1 code here
               MsgBox(0,"","1")
          Case $Number = 2
               ;Do func #2 code here
               MsgBox(0,"","2")
          Case $Number = 3
               ;Do func #3 code here
               MsgBox(0,"","3")
          Case $Number = 4
               ;Do func #4 code here
               MsgBox(0,"","4")
          Case $Number = 5
               ;Do func #5 code here
               MsgBox(0,"","5")
          Case $Number = 6
               ;Do func #6 code here
               MsgBox(0,"","6")
          Case $Number = 7
               ;Do func #7 code here
               MsgBox(0,"","7")
          Case $Number = 8
               ;Do func #8 code here
               MsgBox(0,"","8")
          Case $Number = 9
               ;Do func #9 code here
               MsgBox(0,"","9")
          Case $Number = 10
               ;Do func #10 code here
               MsgBox(0,"","10")
     EndSelect
EndFunc

Ha, I haven't been on these forums since... 2006, almost. Behold, my legacy signature:My AutoIt idol is Valuater. You know you love him, too.My Stuff: D&D AGoT Tools Suite

Share this post


Link to post
Share on other sites

Awesome! Works like a charm NOW... lol

Thanks alot

Share this post


Link to post
Share on other sites

No prob :)


Ha, I haven't been on these forums since... 2006, almost. Behold, my legacy signature:My AutoIt idol is Valuater. You know you love him, too.My Stuff: D&D AGoT Tools Suite

Share this post


Link to post
Share on other sites

Yeah that code could be shorted , but the msgbox was just an example for testing it. Instead of the Msgbox will be functions that are called like the msgbox. :)


--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Share this post


Link to post
Share on other sites

Yeah that code could be shorted , but the msgbox was just an example for testing it. Instead of the Msgbox will be functions that are called like the msgbox. :)

As Dan said, they're just placeholders. However, I don't think that it could be shorted. Using a
For $i = 1 To 10
loop wouldn't allow you to choose a function specific to each number.

Ha, I haven't been on these forums since... 2006, almost. Behold, my legacy signature:My AutoIt idol is Valuater. You know you love him, too.My Stuff: D&D AGoT Tools Suite

Share this post


Link to post
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
Sign in to follow this  
Followers 0