I've been asked by my employer to create an online voting system for internal elections (e.g. board of directors). Our bylaws dictate that we need to use STV.

I wasn't satisfied with the existing software available for counting STV elections, so I rolled my own. Here's how it works:

  1. Shuffle the ballots.
  2. Assign highest-preference votes
    • If the highest-preference candidate has already met the quota, and there aren't enough winners yet, use the ballot's next-highest preference.
    • If the highest-preference candidate came last in the previous round, use the ballot's next-highest preference.
  3. If a ballot's next-highest preference was used, that becomes the "highest preference" in the next round.
  4. Repeat steps 1-3 until there are enough winners.

Here it is in flowchart form:

Flowchart interpretation of the counting process After doing some reading on different counting methods (this comparison [PDF] has proven to be very helpful), I realize that my counting doesn't really fit within the established methods. Here are some of its characteristics:

  • Randomisation is achieved by shuffling all ballots at the beginning of each round, then processing each ballot in sequence.
  • Surplus votes start getting allocated in the middle of the round, as soon as a candidate reaches quota.
  • Surplus votes are allocated to all candidates, not just hopefuls. This means that a candidate who came last in the first round could "come back from the dead". It also means candidates that have already achieved quota could get a few extra votes later on in the round.
  • I use the Cincinnatti method for allocating surplus (a random sample of all ballots), rather than the Irish method.
  • Since the random sample is different for each round, recounts may produce slightly different results
  • Unlike the Wright method, candidates are never definitively excluded.

To be honest, I don't really know if these qualities are good or bad – do they make my method susceptible to vote-rigging? Is it less proportional than another method?

Please let me know what you see as the pros and cons of this counting method. Personally, I think it's easier to understand than the other methods I've come across – but that also means it's probably less robust!

Edit: Here's a sample vote count for an election with 10 candidates competing for 5 seats. 1000 ballots were cast. The Quota is 167.

enter image description here

Delilah receives the fewest first-preference votes. So, in the second round, Delilah is crossed off those 85 ballots and the second preferences are counted.

Greg has the lowest number of votes in round 2, and the same happens to those 105 ballots in the next round. 11 of those happen to have Delilah as their second choice.

  • For clarity, I'm using the Droop formula to calculate the quota.
    – Sam Nabi
    Apr 7, 2017 at 20:35
  • 2
    If "bylaws dictate that we need to use STV", don't you have to use STV? Not make up your own counting system?
    – endolith
    Apr 7, 2017 at 23:13
  • 2
    @endolith there are many many ways to count votes within STV, and our bylaws don't specify the counting method.
    – Sam Nabi
    Apr 8, 2017 at 16:45
  • 3
    Why reinvent the wheel? Why not use on of the STV-PR on-line systems that is already available? Apr 10, 2017 at 9:24
  • Do you allow for a null vote?
    – hszmv
    Nov 6, 2019 at 14:02

4 Answers 4


I think the fact that you never eliminate candidates could be a problem - in same cases you won't even get a result.

Let's say you have 10 candidates trying for 5 slots, and 1000 votes. Each candidate gets between 50-150 votes. But 150 is less then the quota (using the Droop method, the quota would be 1000/[5+1] + 1 = 167) Nobody meets the quota - so how do you determine who wins? In most systems, you'd eliminate the weakest candidate and transfer his votes (and either that puts someone over the quota and you can transfer some other votes, or you keep eliminating candidates until the number of candidates equals the number of seats), but in your system that's not done. Your flowchart would just loop endlessly, counting and re-counting forever.

I'd also point out that, since candidates are never eliminated in your system, if you vote as your first choice a candidate who is not eventually elected, then your second choice will never be counted. I think this goes against the intent of single-transfer voting. I think eliminating a particularly weak candidate actually does a favor to those who voted for that candidate, as it ensures the transfer will kick in.

On another note, I really don't like any randomness in the system. Outcomes should be determined by votes, not by the shuffling algorithm of your software.

  • "if you vote as your first choice a candidate who is not eventually elected, then your second choice will never be counted." - not quite. If your first choice gets crossed off your ballot, then the next choice will be counted. Typically 60-70% of votes elect a winner in the datasets I've tested with.
    – Sam Nabi
    Apr 8, 2017 at 17:35
  • " Nobody meets the quota - so how do you determine who wins?" - good catch. The flowchart oversimplifies this, so actually if the number of seats equals the number of candidates with non-zero vote counts, they are all declared winners. That means they might have less than the quota.
    – Sam Nabi
    Apr 8, 2017 at 17:40
  • 4
    And if there's more to your system than you told us - well, that kind of makes it hard for us to evaluate your system, now doesn't it? :)
    – D M
    Apr 9, 2017 at 4:21
  • 1
    "If your first choice gets crossed off your ballot, then the next choice will be counted." - but I thought you never eliminated anyone. Under what scenario in your system does a weak candidate have his votes transferred?
    – D M
    Apr 9, 2017 at 4:24
  • 3
    What you're doing in the table looks reasonable at first glance, but you may want to put it into words and/or the flowchart. If you can't put the entire process into words, it may not be a good idea to use it in an important election.
    – D M
    Apr 10, 2017 at 6:35

The biggest problem that I see with this is that it is possible to get different results in a recount. So I would never recommend it for a government election. You'd have politicians trying to game the system to get the "right" recount.

One might argue that there are often random tiebreakers, but these operate at the end of the process. So everyone can agree on the recount up to the tiebreaker. Then there is one single random event that they can record. So if the recount has the same result, they can keep the original tiebreaker.

To get a similar result here, you would have to pick the entire random sequence. This is possible. You could randomly pick a seed for a particular pseudorandom algorithm and preserve that choice. But I'm not sure that doing that leaves the system any easier to explain than the other methods. It has a big element of "trust me, I did the random stuff correctly" in it.

  • I've tested this with a few different datasets, and I haven't come across a situation where a recount results in different winners. Of course I will need to do more testing to make sure. But if this pattern holds true, are you still concerned about the randomness involved? (e.g. Each recount takes a different path to arrive at the same result.)
    – Sam Nabi
    Apr 8, 2017 at 16:48
  • 1
    Yes, it would still be a problem. Characteristics of an electoral system need to be proven mathematically, not statistically. Edge cases that are highly improbable will happen sometime in the centuries and you just need to be sure. Statistics can be useful to research a system, but in the end you'll need formal proofs for any property you want to advertise.
    – Rad80
    Nov 14, 2018 at 8:55
  • Non-determinate outcome is a property of STV itself. (without modification) assigning multiple seats makes this less of a problem.
    – bobsburner
    Nov 4, 2019 at 9:18

One key feature of elections is trust in the counting method. Which makes choosing your own system a bit of an issue - not least given the flaws people are picking up on.

There are bodies (such as the UK Electoral Reform Society) with >100 years experience of doing this. They publish a guide on using STV including detailed instructions on how to run a count.

Detailed Instructions for the Count

(This set of instructions is geared towards public paper-based elections - running comparatively small electronic counts should be able to implement this process even more easily)

I strongly suggest you use a proven process by this or a similar organisation. Even if your system was great you would still not have the credibility/confidence/defensibility/validation of something like this.


You can fix this by internally counting it like a Ranked Choice Instant Run off and elimintating the lowest performing candidate each round. If you have 6 candidates and one spot, candidates A, B, C, D, E, F. The ballot will display each candidate with six radio boxes and the voter will choose most favorite to least favorite from left to right (if you want candidate A to win, you mark A with the first radio box. If you want A as your last pick, then you mark A with the sixth radio box.).

All Ballots are placed into a list and the candidates are given results. You then run N Rounds where N is the total number of candidates (6) minus the total number of seats (Lets say 1)

For each round, keep a list of candidates running ranks resulting from the round, with the. To seed the list, list all candidates with the order they appear on the ballot. You want a Round list with the score as your returned objects. Keep the list of ballots constant.

For each round:

Bring in the Master List.

Create a Round list with all results being 0.

Count the ballots

For each ballot: - find the candidate voted first choice (should be marked with a 1) - Add one point to that candidate on the Round List.

Return the Secondary list as the new Master List.

Display Round List Results.

Prune the List:

  • Identify lowest score On Master List.

For all Ballots

  • Find the rank of the lowest scored candidate(s)
  • For all candidates with with lowest score on Round List (check to avoid tied in last place).
  • For all candidates ranked lower than lowest score:
  • --1 to their rank.

Return Ballot List.

Repeat until N candidates remain.

This works because in Ranked Choice Instant Run Off voting, the vote only transfers on elimination in a round. Each round, the remaining candidates will only increase their votes as the eliminated candidates are redistributed. By raising all candidates that were given a lower ballot rank than the biggest loser by one and only counting the candidate scored at one for each round, the rank is preserved as the eliminated candidates vote now goes to that round's number 2, 3 becomes 2, 4 becomes 3 and so on.

By only counting the first choice for each round, we will eventually come to a point where the ballots will only have a first and second choice and the gap becomes narrower. You could even argue that the sixth choice defaults to zero as your sixth choice will never come into play (as at worst, the 51% threshold can be crossed in 5 rounds and at best, the first round. So long you are taking the results of the final round, you can use the results of any round below N. If you have three seats, than you will eliminate 2 candidates and the distribution of the final candidate doesn't matter as the viable candidates are first picks in round four for every voter.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .