Jump to content
prismite

Excluding like-results in loops

Recommended Posts

prismite

Hi all!

Is there a way to utilize this kind of code, but make it so that if the program happens to land on a repeat number it ignores it and reselects?

For $n = 5 to 1 Step -1
   $RandomNumber = RANDOM (1,10,1)
      If $RandomNumber = 1 then FUNC1
      If $RandomNumber = 1 then FUNC2
      If $RandomNumber = 1 then FUNC3
      If $RandomNumber = 1 then FUNC4
      ...
Next

Share this post


Link to post
Share on other sites
Herb191

One way...

#include <Array.au3>

Dim $aNumbers[1]
For $i = 1 To 10 Step 1

$iArraySize = UBound($aNumbers)
    Do
        $RandomNumber = Random(1, 10, 1)
        _ArrayAdd($aNumbers, $RandomNumber)
        $aNumbers = _ArrayUnique($aNumbers, 0, 1)
    Until $iArraySize < UBound($aNumbers)

    ConsoleWrite($RandomNumber & @CRLF)
Next

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.