JASS:
function GroupRandomUnitPick takes group g returns unit
local integer i=0
if tg == null then
set tg=CreateGroup()
endif
loop
set temp[i]=FirstOfGroup(g)
exitwhen temp[i]==null
call BJDebugMsg(GetUnitName(temp[i]))
call GroupAddUnit(tg, temp[i])
call GroupRemoveUnit(g, temp[i])
set i=i+1
endloop
set tempg = g //nothing
set g = tg //something
set tg = tempg //nothing
return temp[GetRandomInt(0,i-1)]
endfunction
The units in group g became non-existent after one call?
NOTE: temp is a unit array and tempg is a group variable