Skip to content

Commit 13969dd

Browse files
committed
Revert "Change to avoid if statements."
This reverts commit 62f6934.
1 parent 62f6934 commit 13969dd

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

axelrod/random_.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
import numpy
33
from axelrod import Actions
44

5-
# A dictionary mapping 0 or 1 probability of cooperating to an action.
6-
choices = {0: Actions.D, 1: Actions.C}
7-
85

96
def random_choice(p=0.5):
107
"""
@@ -23,11 +20,16 @@ def random_choice(p=0.5):
2320
-------
2421
axelrod.Actions.C or axelrod.Actions.D
2522
"""
26-
try:
27-
return choices[p]
28-
except KeyError:
29-
r = random.random()
30-
return choices[r < p]
23+
if p == 0:
24+
return Actions.D
25+
26+
if p == 1:
27+
return Actions.C
28+
29+
r = random.random()
30+
if r < p:
31+
return Actions.C
32+
return Actions.D
3133

3234

3335
def randrange(a, b):

0 commit comments

Comments
 (0)