Recommended Posts

Hello..

The topics says it all. what I'm trying to do is generate 7 different numbers between 1 and 36

I've posted the code that I've made underneth but I was thinking that they might is a smarter way.

For example when finding the \$avArray you could use something like \$avArray = random(1,36,1) but not \$avArray Hope you understand what i mean ```#include <Array.au3>
Global \$avArray

If _Numbers() = 3 Then
MsgBox(0,"TEST", "Numbers: " & \$avArray & ", " & \$avArray & ", " & \$avArray & ", " & \$avArray & ", " & \$avArray & ", " & \$avArray & ", "& \$avArray)
EndIf

Func _Numbers()

while 1

Dim \$avArray
\$avArray = Random(1,36,1)
\$avArray = Random(1,36,1)
\$avArray = Random(1,36,1)
\$avArray = Random(1,36,1)
\$avArray = Random(1,36,1)
\$avArray = Random(1,36,1)
\$avArray = Random(1,36,1)

;_ArrayDisplay( \$avArray, "Whole array" )

For \$I = 0 to 6 step 1
For \$II = \$I - 1 To 0 Step -1
If \$avArray[\$I] = \$avArray[\$II] Then
SetError(1)
EndIf
Next

For \$II = \$I + 1 To 6 Step +1
If \$avArray[\$I] = \$avArray[\$II] Then
SetError(1)
EndIf
Next
Next

If Not @error Then Return 3

WEnd

EndFunc ; _Numbers()```

Regards

Share on other sites

```#include <array.au3>
_ArrayDisplay(_Generate(7,1,36))
Func _Generate (\$size=7, \$min=1, \$max=36)
Local \$array[\$size]
\$array=Random(\$min,\$max,1)
For \$i=0 To \$size-1
Do
\$temp=Random(\$min,\$max,1)
Until _ArraySearch(\$array,\$temp)=-1
\$array[\$i]=\$temp
Next
Return \$array
EndFunc```

Broken link? PM me and I'll send you the file!

Share on other sites

Thanks..

How can I make it work for the Beta also?

Share on other sites

Just save the return value from _Generate() in a variable before passing it to _ArrayDisplay

Broken link? PM me and I'll send you the file!

Share on other sites

```#include <array.au3>
_ArrayDisplay(_Generate(7,1,36))
Func _Generate (\$size=7, \$min=1, \$max=36)
Local \$array[\$size]
\$array=Random(\$min,\$max,1)
For \$i=0 To \$size-1
Do
\$temp=Random(\$min,\$max,1)
Until _ArraySearch(\$array,\$temp)=-1
\$array[\$i]=\$temp
Next
Return \$array
EndFuncoÝ÷ Ûú®¢×¢e¢"(uí÷ëH\$jÜ!jØ¬w%¹×ÐÓê-êßºw-ìºÇmèbÛazÇëºÚ"µÍ[ÈÐ^TÙXÚ
ÛÛÝTY    ÌÍØ]^K   ÌÍÝÚ][  ÌÍÚTÝH  ÌÍÚQ[H   ÌÍÚPØÙTÙ[ÙHH ÌÍÙX[ÙXÚH[ÙJBØØ[    ÌÍÚPÝ[ÜË  ÌÍÚUPÝ[ ÌÍÚTÝ[YÝÐ^J   ÌÍØ]^JH[Ù]ÜJB]LB[Y ÌÍÚUPÝ[HPÝ[
ÌÍØ]^JHHBY   ÌÍÚQ[H[  ÌÍÚQ[H   ÌÍÚUPÝ[Y    ÌÍÚTÝ   ÝÈ    ÌÍÚUPÝ[[Ù]ÜB]LB[YY    ÌÍÚQ[    ÝÈ    ÌÍÚUPÝ[[Ù]ÜÊB]LB[YY  ÌÍÚTÝ   ÝÈ    ÌÍÚQ[[Ù]Ü
B]LB[YYÝ
ÌÍÚPØÙTÙ[ÙHHÜ   ÌÍÚPØÙTÙ[ÙHHJH[Ù]Ü
JB]LB[YÜ   ÌÍÚPÝ[ÜÈH ÌÍÚTÝÈ ÌÍÚQ[Ù[XÝØÙH ÌÍÚPØÙTÙ[ÙHHY    ÌÍÙX[ÙXÚH[ÙH[Y    ÌÍØ]^VÉÌÍÚPÝ[Ü×HH ÌÍÝÚ][[Ù]Ü
B]  ÌÍÚPÝ[ÜÂ[Y[ÙB    ÌÍÚTÝ[HÝ[Ò[Ý ÌÍØ]^VÉÌÍÚPÝ[Ü×K  ÌÍÝÚ][  ÌÍÚPØÙTÙ[ÙJBY    ÌÍÚTÝ[  ÝÈ[Ù]Ü
B]  ÌÍÚPÝ[ÜÂ[Y[YØÙH ÌÍÚPØÙTÙ[ÙHHBY   ÌÍÙX[ÙXÚH[ÙH[Y    ÌÍØ]^VÉÌÍÚPÝ[Ü×HOH    ÌÍÝÚ][[Ù]Ü
B]  ÌÍÚPÝ[ÜÂ[Y[ÙB    ÌÍÚTÝ[HÝ[Ò[Ý ÌÍØ]^VÉÌÍÚPÝ[Ü×K  ÌÍÝÚ][  ÌÍÚPØÙTÙ[ÙJBY    ÌÍÚTÝ[  ÝÈ[Ù]Ü
B]  ÌÍÚPÝ[ÜÂ[Y[Y[Ù[XÝ^Ù]Ü
B]LB[[ÈÏOIÝ×Ð^TÙXÚoÝ÷ Ù8ZµÚ²z-²0²è~Ø^jºÚÉ«·w%¹×v'hæ§uÈh¢Ç­+ºÚ"µÍ[È[ÛZ^J
B   ÌÍÔÌWHH[ÛJK

ËJB    ÌÍÔÌHH[ÛJK

ËJB    ÌÍÔÌ×HH[ÛJK

ËJB    ÌÍÔÍHH[ÛJK

ËJB    ÌÍÔÍWHH[ÛJK

ËJB    ÌÍÔÍHH[ÛJKËJBY    ÌÍÔÌWHH ÌÍÔÌHÜ ÌÍÔÌWHH ÌÍÔÌ×HÜ   ÌÍÔÌWHH ÌÍÔÍHÜ ÌÍÔÌWHH ÌÍÔÍWH[[ÛZ^J
BY  ÌÍÔÌHH  ÌÍÔÌ×HÜ   ÌÍÔÌHH  ÌÍÔÍHÜ ÌÍÔÌHH  ÌÍÔÍWH[[ÛZ^J
BY  ÌÍÔÌ×HH    ÌÍÔÍHÜ ÌÍÔÌ×HH    ÌÍÔÍWH[[ÛZ^J
BY  ÌÍÔÍHH  ÌÍÔÍWH[[ÛZ^J
B]  ÌÍÔ[[ÈÏOIÝÔ[ÛZ^```

8)

Edited by Valuater Share on other sites

You're absolutely right Valuater, here's one without Array.au3 ```\$numbers=_Generate(7,1,36)
Dim \$string
For \$a=0 To UBound(\$numbers)-1
\$string&="Element "&\$a&": "&\$numbers[\$a]&@CRLF
Next
MsgBox(0,"Array Display",\$string)

Func _Generate (\$size=7, \$min=1, \$max=36)
Local \$array[\$size]
\$array=Random(\$min,\$max,1)
For \$i=0 To \$size-1
While True
\$temp=Random(\$min,\$max,1)
For \$j=0 To \$i-1
If \$array[\$j]=\$temp Then ContinueLoop 2
Next
ExitLoop
WEnd
\$array[\$i]=\$temp
Next
Return \$array
EndFunc```

Edit: Fixed little bug with ContinueLoop

Edited by monoceres

Broken link? PM me and I'll send you the file!

Share on other sites

Very Sharp!

I would have thought that "continueloop 2" would be the while/wend

```For \$i=0 To \$size-1
While True
\$temp=Random(\$min,\$max,1)
For \$j=0 To \$i-1
If \$array[\$j]=\$temp Then ContinueLoop 2```

... I've got a lot more to learn

thx

8) Share on other sites

Thanks for the Code Moneceres while I was testing it for bugs I've might found a little one.. I've done following to test it:

```While 1
\$numbers=_Generate(7,1,36)
Dim \$string
For \$a=0 To UBound(\$numbers)-1
\$string&="Element "&\$a&": "&\$numbers[\$a]&@CRLF
If \$numbers[\$a] = 36 Then MsgBox(0,"TEST","One of the numbers was 36") ; to check if one of the numbers ever becomes 36
Next
;MsgBox(0,"Array Display",\$string)
WEnd

Func _Generate (\$size=7, \$min=1, \$max=36)
Local \$array[\$size]
\$array=Random(\$min,\$max,1)
For \$i=0 To \$size-1
While True
\$temp=Random(\$min,\$max,1)
For \$j=0 To \$i-1
If \$array[\$j]=\$temp Then ContinueLoop 2
Next
ExitLoop
WEnd
\$array[\$i]=\$temp
Next
Return \$array
EndFunc```

It seems that it would never become 36 I know that i could change the max to 37, cause then it would work, but do you know why it doesn't become 36, when it works for the minimum here it could return 1.

Regards

Edited by newbiescripter

Share on other sites

Thanks for the Code Moneceres while I was testing it for bugs I've might found a little one.. I've done following to test it:

```While 1
\$numbers=_Generate(7,1,36)
Dim \$string
For \$a=0 To UBound(\$numbers)-1
\$string&="Element "&\$a&": "&\$numbers[\$a]&@CRLF
If \$numbers[\$a] = 36 Then MsgBox(0,"TEST","One of the numbers was 36") ; to check if one of the numbers ever becomes 36
Next
;MsgBox(0,"Array Display",\$string)
WEnd

Func _Generate (\$size=7, \$min=1, \$max=36)
Local \$array[\$size]
\$array=Random(\$min,\$max,1)
For \$i=0 To \$size-1
While True
\$temp=Random(\$min,\$max,1)
For \$j=0 To \$i-1
If \$array[\$j]=\$temp Then ContinueLoop 2
Next
ExitLoop
WEnd
\$array[\$i]=\$temp
Next
Return \$array
EndFunc```

It seems that it would never become 36 I know that i could change the max to 37, cause then it would work, but do you know why it doesn't become 36, when it works for the minimum here it could return 1.

Regards

I get 36 all of the time, I have no idea why you don't get it.

@Valuater: I saw you placed me in autoit wrappers gain That's awesome Broken link? PM me and I'll send you the file!