Jump to content

checking random results


Recommended Posts

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

Link to comment
Share on other sites

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
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...