Well, for vehicles it seems to match a number which is related to the weapon position in the weapons unit array and the (modes of each weapon read from cfgweapons max 1).
For example, weapons = [A,B,C], A has two modes, B has none (so it counts as 1) and C has none, the weapon index for C is 2 + 1 = 3. But this becomes false for soldiers, with soldiers I've tried to add not only modes but also muzzles, and again the resulting number doesnt match the real index. And soldiers might have the unlisted weapons Throw and Put, so it becomes even more tricky. Anyway there should be a logic behind that, it cannot be a so chaotic number as it seems at first sight.