Jump to content

Random function?


Recommended Posts

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!

Link to comment
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
Link to comment
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
Link to comment
Share on other sites

Not to detract from JoshDB's code, it works like a charm, but... you could do the same thing with alot less typing.

While 1
    MsgBox(0, "", "Hello" & Random(1, 10, 1))
WEnd

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Link to comment
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]

Link to comment
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
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...