Jump to content

Making a randomized list


 Share

Recommended Posts

I've got a list of 16 people, and I want them sorted into 4 random teams of 4. Halo 2 party this weekend :)

Dim $NAME[16], $SPOT[16]
$NAME[0] = "Jack"
$NAME[1] = "Keegan"
$NAME[2] = "Clark"
$NAME[3] = "Peter"
$NAME[4] = "Tom"
$NAME[5] = "Austin"
$NAME[6] = "Jacob"
$NAME[7] = "Jory"
$NAME[8] = "Justin"
$NAME[9] = "Marcus"
$NAME[10] = "Kalhid"
$NAME[11] = "Adam"
$NAME[12] = "Taylor"
$NAME[13] = "Luke"
$NAME[14] = "Ben"
$NAME[15] = "Ethan"
$S = 0

While 1
   $I = Round(Random(0, 15), 0)
   ToolTip($S, 0, 0)
   If $NAME[$I] = 0 Then ContinueLoop
   $SPOT[$S] = $NAME[$I]
   $NAME[$I] = 0
   $S = $S + 1
   If $S > 15 Then
      ExitLoop
   EndIf
Wend

MsgBox(0, "Halo 2", "Team 1:" & $SPOT[0] & ", " & $SPOT[1] & ", " & $SPOT[2] & ", " & $SPOT[3] & @CRLF & "Team 2:" & $SPOT[4] & ", " & $SPOT[5] & ", " & $SPOT[6] & ", " & $SPOT[7] & @CRLF & "Team 3:" & $SPOT[8] & ", " & $SPOT[9] & ", " & $SPOT[10] & ", " & $SPOT[11] & @CRLF & "Team 4:" & $SPOT[12] & ", " & $SPOT[13] & ", " & $SPOT[14] & ", " & $SPOT[15])

For some reason, it won't assign anybody to anywhere...

Could someone either A.) Fix my script, or B.) Supply your own replacement script?

Thankee :)

Link to comment
Share on other sites

Not the most efficient way, but this should get you through it.

Dim $NAME[18], $SPOT[18]
$NAME[0] = "Jack"
$NAME[1] = "Keegan"
$NAME[2] = "Clark"
$NAME[3] = "Peter"
$NAME[4] = "Tom"
$NAME[5] = "Austin"
$NAME[6] = "Jacob"
$NAME[7] = "Jory"
$NAME[8] = "Justin"
$NAME[9] = "Marcus"
$NAME[10] = "Kalhid"
$NAME[11] = "Adam"
$NAME[12] = "Taylor"
$NAME[13] = "Luke"
$NAME[14] = "Ben"
$NAME[15] = "Ethan"
$S = 0
$names="|"
While 1
  $I = int(Random(0,16))
  ToolTip($S, 0, 0)
If StringInStr($names,"|" & $name[$i])>0 and $s<15 Then
    ContinueLoop
Else
    $names=$names&$name[$i]&"|"
$SPOT[$s]=$name[$i]
$s=$s+1
EndIf
If $s>16 Then ExitLoop
Wend

MsgBox(0, "Halo 2", "Team 1:" & $SPOT[0] & ", " & $SPOT[1] & ", " & $SPOT[2] & ", " & $SPOT[3] & @CRLF & "Team 2:" & $SPOT[4] & ", " & $SPOT[5] & ", " & $SPOT[6] & ", " & $SPOT[7] & @CRLF & "Team 3:" & $SPOT[8] & ", " & $SPOT[9] & ", " & $SPOT[10] & ", " & $SPOT[11] & @CRLF & "Team 4:" & $SPOT[12] & ", " & $SPOT[13] & ", " & $SPOT[14] & ", " & $SPOT[15])
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Thanks, scriptkitty, that works... for the most part, EXCEPT:

The last name is always duplicated somewhere.

EDIT: Nevermind, I fixed it.

If StringInStr($NAMES, "|" & $NAME[$I]) > 0 And $S < 15 Then

had to be changed to

If StringInStr($NAMES, "|" & $NAME[$I]) > 0 And $S < 16 Then
Edited by Sunblood
Link to comment
Share on other sites

Added this if you wanted to change to 2 teams of 8 or such. :)

Dim $NAME[16], $SPOT[16]
$NAME[0] = "Jack"
$NAME[1] = "Keegan"
$NAME[2] = "Clark"
$NAME[3] = "Peter"
$NAME[4] = "Tom"
$NAME[5] = "Austin"
$NAME[6] = "Jacob"
$NAME[7] = "Jory"
$NAME[8] = "Justin"
$NAME[9] = "Marcus"
$NAME[10] = "Kalhid"
$NAME[11] = "Adam"
$NAME[12] = "Taylor"
$NAME[13] = "Luke"
$NAME[14] = "Ben"
$NAME[15] = "Ethan"
$S = 0
$names="|"
While 1
 $I = int(Random(0,16))
 ToolTip($S, 0, 0)
If StringInStr($names,"|" & $name[$i])>0 Then
   ContinueLoop
Else
   $names=$names&$name[$i]&"|"
$SPOT[$s]=$name[$i]
$s=$s+1
EndIf
If $s>15 Then ExitLoop
Wend

$output=""
$count=0
$perteam=4
$teams=4
For $team=1 To $teams
    $output=$output & @CRLF &"Team " & $team & ":"
    For $players=1 To $perteam
        $output=$output & $spot[$count] & ","
        $count=$count+1
    Next
    $output=StringTrimRight($output,1)
Next
MsgBox(1,"Halo 2-->",$output)

AutoIt3, the MACGYVER Pocket Knife for computers.

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