SCRMaps
/
Sign in

Building a real random number out of switches

One switch is one coin flip. Several of them, read as digits, make a number.

5 min read

StarCraft has no random number action. What it has is randomising a switch, which comes out Set or Cleared - zero or one. One binary digit.

So use several digits. Just as the 4 in 1423 means 400, a 1 in the second binary place means 2 and in the third means 4. Three places give you eight outcomes, 0 through 7.

  1. 1Randomise the switch.
  2. 2If it is Set, add 1 to a death counter. If Cleared, do nothing.
  3. 3Randomise again, and add 2 if Set.
  4. 4Randomise again, and add 4 if Set.
  5. 5The counter now holds a number from 0 to 7.

You do not need a trigger for the Cleared case: adding nothing is adding zero. And remember to reset the counter to zero before the next draw.

If the number of outcomes is not a power of two it does not divide cleanly. Six outcomes from three digits leaves 6 and 7 over, and folding those onto other results makes those results twice as likely - a bias that appears silently. Re-drawing when you land on a leftover is the honest fix.

Sign in to track your progress