newbiescripter Posted May 2, 2008 Share Posted May 2, 2008 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[1] you could use something like $avArray[1] = random(1,36,1) but not $avArray[0] Hope you understand what i mean expandcollapse popup#include <Array.au3> Global $avArray If _Numbers() = 3 Then MsgBox(0,"TEST", "Numbers: " & $avArray[0] & ", " & $avArray[1] & ", " & $avArray[2] & ", " & $avArray[3] & ", " & $avArray[4] & ", " & $avArray[5] & ", "& $avArray[6]) EndIf Func _Numbers() while 1 Dim $avArray[7] $avArray[0] = Random(1,36,1) $avArray[1] = Random(1,36,1) $avArray[2] = Random(1,36,1) $avArray[3] = Random(1,36,1) $avArray[4] = Random(1,36,1) $avArray[5] = Random(1,36,1) $avArray[6] = 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 Link to comment Share on other sites More sharing options...
monoceres Posted May 2, 2008 Share Posted May 2, 2008 Tada! #include <array.au3> _ArrayDisplay(_Generate(7,1,36)) Func _Generate ($size=7, $min=1, $max=36) Local $array[$size] $array[0]=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! Link to comment Share on other sites More sharing options...
newbiescripter Posted May 2, 2008 Author Share Posted May 2, 2008 Thanks.. How can I make it work for the Beta also? Link to comment Share on other sites More sharing options...
monoceres Posted May 2, 2008 Share Posted May 2, 2008 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! Link to comment Share on other sites More sharing options...
Valuater Posted May 2, 2008 Share Posted May 2, 2008 (edited) Tada! expandcollapse popup#include <array.au3> _ArrayDisplay(_Generate(7,1,36)) Func _Generate ($size=7, $min=1, $max=36) Local $array[$size] $array[0]=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 May 2, 2008 by Valuater Link to comment Share on other sites More sharing options...
monoceres Posted May 2, 2008 Share Posted May 2, 2008 (edited) 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[0]=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 May 3, 2008 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Valuater Posted May 3, 2008 Share Posted May 3, 2008 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) Link to comment Share on other sites More sharing options...
newbiescripter Posted May 3, 2008 Author Share Posted May 3, 2008 (edited) 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[0]=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 May 3, 2008 by newbiescripter Link to comment Share on other sites More sharing options...
monoceres Posted May 4, 2008 Share Posted May 4, 2008 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[0]=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. RegardsI 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! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now