Author: humbedooh
Date: Fri Apr 3 08:20:05 2015
New Revision: 1671014
URL: http://svn.apache.org/r1671014
Log:
seed based on no. of votes cast - this way it stays semi-random, but never
changes once an election is over.
Modified:
steve/trunk/pysteve/lib/plugins/stv.py
Modified: steve/trunk/pysteve/lib/plugins/stv.py
URL:
http://svn.apache.org/viewvc/steve/trunk/pysteve/lib/plugins/stv.py?rev=1671014&r1=1671013&r2=1671014&view=diff
==============================================================================
--- steve/trunk/pysteve/lib/plugins/stv.py (original)
+++ steve/trunk/pysteve/lib/plugins/stv.py Fri Apr 3 08:20:05 2015
@@ -43,7 +43,7 @@ def validateSTV(vote, issue):
def run_vote(names, votes, num_seats):
- candidates = CandidateList(names)
+ candidates = CandidateList(names, votes)
# name -> Candidate
remap = dict((c.name, c) for c in candidates.l)
@@ -74,9 +74,9 @@ def run_vote(names, votes, num_seats):
class CandidateList(object):
- def __init__(self, names):
+ def __init__(self, names, votes):
num_cand = len(names)
- randset = generate_random(num_cand)
+ randset = generate_random(num_cand, votes)
self.l = [ ]
for n, r in zip(names, randset):
@@ -311,9 +311,8 @@ def exclude_lowest(candidates):
which.eliminate()
-def generate_random(count):
- random.seed(time.time()) # Seed based on current time.
- while True:
+def generate_random(count, votes):
+ random.seed(len(votes)) # Seed based on number of votes
# Generate COUNT values in [0.0, 1.0)
values = [random.random() for x in range(count)]