gamerman2360 Posted October 14, 2006 Share Posted October 14, 2006 (edited) The functions probably need to be renamed. :shrug: Made to handle big numbers. (First went with a single dementional array with names in it... AutoIt wasn't too happy.)expandcollapse popup#region Testing AppendEntree($data, "One", 1) AppendEntree($data, "Two", 2) AppendEntree($data, "Three", 3) AppendEntree($data, "Four", 4) AppendEntree($data, "Five", 5) AppendEntree($data, "Six", 6) AppendEntree($data, "Seven", 7) AppendEntree($data, "Eight", 8) AppendEntree($data, "Nine", 9) AppendEntree($data, "Ten", 10) $msg = $data[0][0] & " entree" & Plural($data[0][0]) & ", " & $data[0][1] & " ticket" & Plural($data[0][1]) & "." For $i = 1 To UBound($data) - 1 If $data[$i][1] == 1 Then $plural = "" Else $plural = "s" EndIf $msg &= @CRLF & $data[$i][0] & " has purchaced " & $data[$i][1] & " ticket" & Plural($data[$i][1]) & "." Next $msg &= @CRLF For $i = 1 To 3 $msg &= @CRLF & "Winner #" & $i & " is " & PickTicket($data, 1) & "." Next $msg &= @CRLF For $i = 1 To UBound($data) - 1 $msg &= @CRLF & $data[$i][0] & " has won " & $data[$i][2] & " time" & Plural($data[$i][2]) & "." Next MsgBox(0, "Test", $msg) Func Plural($value) If $value = 1 Then $return = "" Else $return = "s" EndIf Return $return EndFunc #endregion #cs $data[0][0]: number of entrees $data[0][1]: number of total tickets $data[0][2]: number of total wins $data[$i][0]: entree name $data[$i][1]: number of entree tickets $data[$i][2]: number of entree wins #ce Func OnAutoItStart() Global $data[1][3] = [[0, 0, 0]] EndFunc Func AppendEntree(ByRef $array, $name, $quantity) ReDim $array[UBound($array) + 1][3] $array[0][0] += 1 $array[0][1] += $quantity $array[$array[0][0]][0] = $name $array[$array[0][0]][1] = $quantity $array[$array[0][0]][2] = 0; num of wins EndFunc Func PickTicket(ByRef $array, $onlyWinOncePerTicket = 0) $validTickets = $array[0][1] If $onlyWinOncePerTicket Then $validTickets -= $array[0][2] $pick = Random(1, $validTickets, 1) Local $i; to get after the loop For $i = 1 To $array[0][0] If $onlyWinOncePerTicket Then $pick += $array[$i][2] $pick -= $array[$i][1] If $pick <= 0 Then ExitLoop Next $array[0][2] += 1 $array[$i][2] += 1 Return $array[$i][0] EndFunc Edited October 14, 2006 by gamerman2360 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