Jump to content

Problem with random in a loop


Recommended Posts

If I run Random in a loop it returns the original random number it returned. I need random in a loop, so is there anyway to run it without it returning the same number over and over again?

While 1

msgBox(0, "Roll of die", "You rolled a " & Random(1, 6, 1) )

WEnd

Link to comment
Share on other sites

The code you posted does not return the same number over and over again for me. Each time the message box pops up, I get a different number from 1 to 6. Is it returning the same number for you every time the message box pops up?? Or is that not what you meant? You could also toss an Srandom in the loop if that helps, but it shouldn't be returning the same number over and over again.

Link to comment
Share on other sites

If I run Random in a loop it returns the original random number it returned. I need random in a loop, so is there anyway to run it without it returning the same number over and over again?

While 1

msgBox(0, "Roll of die", "You rolled a " & Random(1, 6, 1) )

WEnd

This?:

#include <Array.au3>

Global $aNumber[7]
$aNumber[0] = 6

For $i = 1 To $aNumber[0]
    While 1
        $iRandom = Random(1, 6, 1)
        _ArraySearch($aNumber, $iRandom, 1)
        If @error Then ExitLoop
    WEnd
    $aNumber[$i] = $iRandom
    MsgBox(0, "Random", $iRandom)
Next
:)
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...