function GetRandomSubGroup takes integer count, group sourceGroup returns group
local group g = CreateGroup()
set bj_randomSubGroupGroup = g
set bj_randomSubGroupWant = count
set bj_randomSubGroupTotal = CountUnitsInGroup(sourceGroup)
if (bj_randomSubGroupWant <= 0 or bj_randomSubGroupTotal <= 0) then
return g
endif
set bj_randomSubGroupChance = I2R(bj_randomSubGroupWant) / I2R(bj_randomSubGroupTotal)
call ForGroup(sourceGroup, function GetRandomSubGroupEnum)
return g
endfunction