| 12-10-2008, 02:45 AM | #1 |
JASS:function GroupGetRandomUnit takes group g returns unit local integer count = CountUnitsInGroup(g) local integer r local unit fog local integer i = 1 local group ng = NewGroup() set r = GetRandomInt(1, count) call BJDebugMsg(I2S(r)) call GroupAddGroupAdv(g,ng) loop set fog = FirstOfGroup(ng) exitwhen fog == null call BJDebugMsg(GetUnitName(fog)) call BJDebugMsg(I2S(i)) if r == i then set ru = fog endif set i = i + 1 call GroupRemoveUnit(ng, fog) endloop set fog = null call ReleaseGroup(ng) set ng = null return ru endfunction this code runs once per game. however, random int r returns 1 every single time. (ive unchecked fixed random seeds and tested on bnet) also, i created a map init trigger to show a random integer at the start of every game and suprisingly, they were all different.. why isn't this one random? |
| 12-10-2008, 02:49 AM | #2 |
add: call BJDebugMsg(I2S(count)) |
| 12-10-2008, 03:00 AM | #3 |
did u run any cinematic before running your codes? |
| 12-10-2008, 03:29 AM | #4 |
FIXED: turns out the save/load i was using used SetRandomSeed in it. Count returns 1 > did u run any cinematic before running your codes? no JASS:globals private integer count endglobals private function Count takes nothing returns nothing set count = count + 1 endfunction function GroupGetRandomUnit takes group g returns unit local integer r local unit fog local integer i = 1 local group ng = NewGroup() set count = 0 call GroupAddGroupAdv(g,ng) call ForGroup(ng, function Count) call BJDebugMsg(I2S(count)) set r = GetRandomInt(1, 6) call BJDebugMsg(I2S(r)) loop set fog = FirstOfGroup(ng) exitwhen fog == null call BJDebugMsg(GetUnitName(fog)) call BJDebugMsg(I2S(i)) if r == i then set ru = fog endif set i = i + 1 call GroupRemoveUnit(ng, fog) endloop set fog = null call ReleaseGroup(ng) set ng = null return ru endfunction changed to that, count now returns 6, but randomint(1,count) always returns 5. fixed random seed is unchecked. JASS:function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing call BJDebugMsg(I2S(GetRandomInt(1,6))) call BJDebugMsg(I2S(GetRandomInt(1,6))) call BJDebugMsg(I2S(GetRandomInt(1,6))) call BJDebugMsg(I2S(GetRandomInt(1,6))) call BJDebugMsg(I2S(GetRandomInt(1,6))) endfunction //=========================================================================== function InitTrig_Untitled_Trigger_001 takes nothing returns nothing set gg_trg_Untitled_Trigger_001 = CreateTrigger( ) call TriggerRegisterTimerEventSingle( gg_trg_Untitled_Trigger_001, 5 ) call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions ) endfunction Test 1 2 1 4 4 4 Test 2 3 3 6 6 2 this proves its not fixed random seed FIXED: turns out the save/load i was using used SetRandomSeed in it. |
