Jump to content

Lotto number generator


Recommended Posts

Hello,

I have created a Lotto Generator for fun.

#include <Array.au3>
#include <GuiConstants.au3>

Dim $R[11]
Dim $Getal1


; GUI
GuiCreate("Lucky Day Generator", 240, 80, -1, -1)
;GuiCreate("Lucky Day Generator", 240, 120, -1, -1, $WS_BORDER, $WS_EX_TOPMOST)

GUICtrlCreateLabel(" ",5 ,20, 240)
GUICtrlCreateLabel("Lucky nummers : " ,5, 20)

GUISetState()

$Genereer = GUICtrlCreateButton("Genereer", 30, 50, 75, 23)
$Stoppen = GUICtrlCreateButton("Stoppen", 135, 50, 75, 23) 

While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $Stoppen Then ExitLoop
    
    If $msg = $Genereer Then
        
        Randomize()
        GUICtrlCreateLabel(" ",5 ,20, 240)
        GUICtrlCreateLabel("Lucky nummers : " & $Getal1, 5, 20)
            
    EndIf
WEnd

Func Randomize()
$R[1] = Random(1, 80, 1)
$R[2] = Random(1, 80, 1)
$R[3] = Random(1, 80, 1)
$R[4] = Random(1, 80, 1)
$R[5] = Random(1, 80, 1)
$R[6] = Random(1, 80, 1)
$R[7] = Random(1, 80, 1)
$R[8] = Random(1, 80, 1)
$R[9] = Random(1, 80, 1)
$R[10] = Random(1, 80, 1)

If $R[1] = $R[2] Or $R[1] = $R[3] Or $R[1] = $R[4] Or $R[1] = $R[5] Or $R[1] = $R[6] Or $R[1] = $R[7] Or $R[1] = $R[8] Or $R[1] = $R[9] Or $R[1] = $R[10] Then Randomize ()
If $R[2] = $R[3] Or $R[2] = $R[4] Or $R[2] = $R[5] Or $R[2] = $R[6] Or $R[2] = $R[7] Or $R[2] = $R[8] Or $R[2] = $R[9] Or $R[2] = $R[10] Then Randomize ()
If $R[3] = $R[4] Or $R[3] = $R[5] Or $R[3] = $R[6] Or $R[3] = $R[7] Or $R[3] = $R[8] Or $R[3] = $R[9] Or $R[3] = $R[10] Then Randomize ()
If $R[4] = $R[5] Or $R[4] = $R[6] Or $R[4] = $R[7] Or $R[4] = $R[8] Or $R[4] = $R[9] Or $R[4] = $R[10] Then Randomize ()
If $R[5] = $R[6] Or $R[5] = $R[7] Or $R[5] = $R[8] Or $R[5] = $R[9] Or $R[5] = $R[10] Then Randomize ()
If $R[6] = $R[7] Or $R[6] = $R[8] Or $R[6] = $R[9] Or $R[6] = $R[10] Then Randomize ()
If $R[7] = $R[8] Or $R[7] = $R[9] Or $R[7] = $R[10] Then Randomize ()
If $R[8] = $R[9] Or $R[8] = $R[10] Then Randomize ()
If $R[9] = $R[10] Then Randomize ()
_ArraySort($R, 0, 1)
$Getal1 = $r[1]&" "&$r[2]&" "&$r[3]&" "&$r[4]&" "&$r[5]&" "&$r[6]&" "&$r[7]&" "&$r[8]&" "&$r[9]&" "&$r[10]


EndFunc

Is this the best way or could it be made easier? The long If statements are for that I get unique numbers and not the same.

John

Link to comment
Share on other sites

Define easier.

How is this looking?

#include <Array.au3>

Local $aRandom[11] = ["Generated numbers"]

For $i = 1 To 10
    $aRandom[$i] = Random(1, 80, 1)
    For $j = 1 To $i
        If $i = $j Then ContinueLoop
        If $aRandom[$i] = $aRandom[$j] Then $i -= 1
    Next
Next

_ArrayDisplay($aRandom, "Lotto")
Link to comment
Share on other sites

Another way (most usefull if you want a random order of whole array or lot of this) is this:

#include <Array.au3>
$ret = _Lotto()
;~ $ret = _Lotto(6, 49)

_ArraySort($ret, 0, 1)
_ArrayDisplay($ret)

Func _Lotto($iCount=10, $iRange=80)
    Local $aRange[$iRange], $rnd, $aOut[$iCount+1] = [$iCount]
    For $i = 0 To $iRange -1
        $aRange[$i] = $i +1
    Next
    For $i = 1 To $iCount
        $rnd = Random(0,$iRange-1,1)
        $aOut[$i] = Number($aRange[$rnd])
        $aRange[$rnd] = $aRange[$iRange-1]
        $iRange -= 1
    Next
    Return $aOut
EndFunc

With setting value as Number() it's possible to sort array numeric.

Best Regards BugFix  

Link to comment
Share on other sites

Define easier.

How is this looking?

#include <Array.au3>

Local $aRandom[11] = ["Generated numbers"]

For $i = 1 To 10
    $aRandom[$i] = Random(1, 80, 1)
    For $j = 1 To $i
        If $i = $j Then ContinueLoop
        If $aRandom[$i] = $aRandom[$j] Then $i -= 1
    Next
Next

_ArrayDisplay($aRandom, "Lotto")

Hi,

Easier as in smaller like you did. Looks great. Thanks for the input.

Link to comment
Share on other sites

Hi,

I have used this code :

#include <Array.au3>

$Numbers = 10
$Range = 80
Local $aRandom[$Numbers+1] = ["Generated numbers"]

For $i = 1 To $Numbers
    $aRandom[$i] = Random(1, $Range, 1)
    For $j = 1 To $i
        If $i = $j Then ContinueLoop
        If $aRandom[$i] = $aRandom[$j] Then $i -= 1
    Next
    $Result1 = $aRandom[$i] & $Result1
Next

_ArraySort($aRandom ,0 ,1)
;_ArrayDisplay($aRandom, "Lotto") 
 
 $Result1 = $aRandom[1]&" "&$aRandom[2]&" "&$aRandom[3]&" "&$aRandom[4]&" "&$aRandom[5]

 MsgBox ( 4096, "Test", $Result1 )

Is it possible to make $Result1 = $Result1&" "&$aRandom[$i]&" " so that the results get added in one line.

Link to comment
Share on other sites

Hi,

yes it is:

#include <Array.au3>

$Numbers = 10
$Range = 80
Local $aRandom[$Numbers+1] = ["Generated numbers"]

For $i = 1 To $Numbers
    $aRandom[$i] = Random(1, $Range, 1)
    For $j = 1 To $i
        If $i = $j Then ContinueLoop
        If $aRandom[$i] = $aRandom[$j] Then $i -= 1
    Next
Next

_ArraySort($aRandom ,0 ,1)
 
$result1 = _ArrayToString ($aRandom, " ")
$result2 = _ArrayToString ($aRandom, " ", 1)
MsgBox ( 4096, "Test", "Result 1: " & $result1 & @CRLF & "Result 2: " & $result2)

;-))

Stefan

@Edit: Version with unsorted result string and some code changes:

#include <Array.au3>

$Numbers = 10
$Range = 80
Local $aRandom[$Numbers+1] = ["Generated numbers"], $result3 = ""

For $i = 1 To $Numbers
    $bfind = True
    $Random = Random(1, $Range, 1)
    If _ArraySearch ($aRandom, $Random) < 1 Then
        $aRandom [$i] = $Random
    Else
        $i -= 1
        $bfind = False
    EndIf
    If $bfind Then $result3 &= $aRandom[$i] & " "
Next
$result3 = StringTrimRight ($result3, 1)
_ArraySort($aRandom ,0 ,1)
 
$result1 = _ArrayToString ($aRandom, " ")
$result2 = _ArrayToString ($aRandom, " ", 1)
MsgBox ( 4096, "Test", "Result 1: " & $result1 & @CRLF & "Result 2: " & $result2 & @CRLF & "Result 3: " & $result3)
Edited by 99ojo
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...