SCRMaps
/
Sign in

Drops and probability

Randomised switches are where probability comes from.

7 min read

Classic triggers have no random function. What they have is SetSwitch with Randomize, which flips a switch on or off at random. One switch is exactly 50%, so stacking them builds other odds.

Trigger { -- 보스가 죽으면 주사위를 굴린다
	players = {Force1},
	conditions = {
		Kills(CurrentPlayer, AtLeast, 1, "Boss Unit");
	},
	actions = {
		SetKills(CurrentPlayer, SetTo, 0, "Boss Unit");
		SetSwitch("Drop A", Randomize);
		SetSwitch("Drop B", Randomize);
		SetDeaths(CurrentPlayer, SetTo, 1, "RollDrop");
		PreserveTrigger();
	},
}

Trigger { -- 둘 다 켜졌을 때만 = 25%
	players = {Force1},
	conditions = {
		Deaths(CurrentPlayer, Exactly, 1, "RollDrop");
		Switch("Drop A", Set);
		Switch("Drop B", Set);
	},
	actions = {
		SetDeaths(CurrentPlayer, SetTo, 0, "RollDrop");
		CreateUnit(1, "Rare Item", "Player Start", CurrentPlayer);
		DisplayText("\x13\x03희귀 아이템을 획득했습니다!");
		PreserveTrigger();
	},
}
Two switches both on is one chance in four; three gives one in eight.

Switches are shared by the whole map, so two players rolling at once overwrite each other. That is why the roll is marked with a per-player counter and resolved inside the same cycle.

Odds like 25% or 12.5% are easy; 10% or 3% cannot be hit exactly this way. When you need a precise chance, that is what EUD's f_rand is for.

Even after moving to EUD, "is this actually random" is a separate question. Complaints that random team assignment leans one way come up often, and the cause is usually the seed rather than the algorithm.

What to know about the seed
randomize() is the old functionIt is unchanged since 1.16.1 and builds a 32-bit seed by running the random switch 32 times.
Drawing more numbers does not make them more randomStarCraft's generator is an LCG, and an LCG's linear structure is not broken by calling it more often - drawing every frame buys no quality at all.
A seed derived from a weak seed is weakDerive your seed from StarCraft's LCG and it is as predictable as the LCG is.
% n is biasedModulo has bias. Where the distribution matters, use rejection sampling instead of % n.

The cheapest real improvement is to gather the seed from several hard-to-predict sources and run it through a mixer - game time, frame count, the room title, the nickname. And keep your own stream separate from the game's: save the game's seed with getseed, srand to yours, draw, save yours back, then restore the game's. Otherwise your draws push the game's sequence along and its draws push yours.

Sign in to track your progress