diff --git a/axelrod/moran.py b/axelrod/moran.py index e94b3ef23..534e6906f 100644 --- a/axelrod/moran.py +++ b/axelrod/moran.py @@ -7,6 +7,7 @@ from .deterministic_cache import DeterministicCache from .match import Match from .player import Player +from .random_ import randrange def fitness_proportionate_selection(scores): @@ -58,7 +59,7 @@ def __next__(self): # Fitness proportionate selection j = fitness_proportionate_selection(scores) # Randomly remove a strategy - i = random.randrange(0, len(self.players)) + i = randrange(0, len(self.players)) # Replace player i with clone of player j self.players[i] = self.players[j].clone() self.populations.append(self.population_distribution()) diff --git a/axelrod/random_.py b/axelrod/random_.py index 3c614ff50..1d5decfa6 100644 --- a/axelrod/random_.py +++ b/axelrod/random_.py @@ -12,3 +12,9 @@ def random_choice(p=0.5): if r < p: return Actions.C return Actions.D + +def randrange(a, b): + """Python 2 / 3 compatible randrange.""" + c = b - a + r = c * random.random() + return a + int(r) \ No newline at end of file