Sign in to follow this  
Followers 0
alfa

checking random results

9 posts in this topic

hello ,

i want to roll 4 random numbers , this part is easy :unsure:

But i want to check and reroll if there are any same numbers.

Thanks in advance

Share this post


Link to post
Share on other sites



Assign the random number a variable, split the number, then run checks against the new re-roll. Post some example code that you have already started working on.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

hello ,

i want to roll 4 random numbers , this part is easy :unsure:

But i want to check and reroll if there are any same numbers.

Thanks in advance

Something like this ?

#include <Array.au3>

Global $_Array[1]

While 1
   $_Var = Random ( 1, 20, 1 )
   If Not _AlreadyInArray ( $_Array, $_Var ) Then _ArrayAdd ( $_Array, $_Var )
   If UBound ( $_Array ) -1 = 4 Then ExitLoop
WEnd

_ArrayDisplay ( $_Array )

Func _AlreadyInArray ( $_SearchArray, $_Item )
    $_Index = _ArraySearch ( $_SearchArray, $_Item )
    If @error Then
        Return False
    Else
        If  $_Index <> 0 Then
            Return True
        Else
            Return False
        EndIf
    EndIf
EndFunc ;==> _AlreadyInArray ( )
Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Why _ArraySearch()?

#Include <Array.au3>

Dim $Val[4]

For $i = 0 To UBound($Val) - 1
    While 1
        $Val[$i] = Random(0, 100, 1)
        For $j = 0 To $i - 1
            If $Val[$i] = $Val[$j] Then
                ContinueLoop 2
            EndIf
        Next
        ContinueLoop 2
    WEnd
Next

_ArrayDisplay($Val)
Edited by Yashied

Share this post


Link to post
Share on other sites

Why _ArraySearch()?

For searching like your loop ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

wow you guys make it look real easy :S

one last thing how can i make these numbers sort ?

Share this post


Link to post
Share on other sites

Use _ArraySort function ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Thanks a lot again :unsure:

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