GetRandomSubGroup function in Blizzard.j has a subtle bug. The chance of picking multiple identical units can be different.
For instance, if we want to pick 2 random units from a group of 3 units: (a, b, c). Then we call GetRandomSubGroup in Blizzard.j, and it turns out like following:
The chance of getting (a, b) out of (a, b, c) is 4/9
The chance of getting (a, c) out of (a, b, c) is 2/9
The chance of getting (b, c) out of (a, b, c) is 1/3
Here's how I fixed this problem by overwriting blizzard.j function
In GetRandomSubGroupEnum function, when it goes through the group, it never changes the chance of picking subgroup units. However the size of remaining subgroup is decreasing each time it enums, which has caused the problem.
I wonder if anyone found that already but I've searched it and couldn't find any thread that mentioned it.
For instance, if we want to pick 2 random units from a group of 3 units: (a, b, c). Then we call GetRandomSubGroup in Blizzard.j, and it turns out like following:
The chance of getting (a, b) out of (a, b, c) is 4/9
The chance of getting (a, c) out of (a, b, c) is 2/9
The chance of getting (b, c) out of (a, b, c) is 1/3
Here's how I fixed this problem by overwriting blizzard.j function
JASS:
function GetRandomSubGroupEnum takes nothing returns nothing
if (bj_randomSubGroupWant > 0) then
if (bj_randomSubGroupWant >= bj_randomSubGroupTotal) or (GetRandomReal(0,1) < bj_randomSubGroupChance) then
// We either need every remaining unit, or the unit passed its chance check.
call GroupAddUnit(bj_randomSubGroupGroup, GetEnumUnit())
set bj_randomSubGroupWant = bj_randomSubGroupWant - 1
endif
endif
set bj_randomSubGroupTotal = bj_randomSubGroupTotal - 1
// Fixed by: xylign
if (bj_randomSubGroupTotal > 0) then
set bj_randomSubGroupChance = bj_randomSubGroupWant / I2R(bj_randomSubGroupTotal)
endif
endfunction
In GetRandomSubGroupEnum function, when it goes through the group, it never changes the chance of picking subgroup units. However the size of remaining subgroup is decreasing each time it enums, which has caused the problem.
I wonder if anyone found that already but I've searched it and couldn't find any thread that mentioned it.