Sign in to follow this  
Followers 0
EscapeTheFate

Problem with random in a loop

4 posts in this topic

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

Share this post


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

Share this post


Link to post
Share on other sites

So, I'm guessing the OP only ran the code twice and got the same number?

Share this post


Link to post
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
:)

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