-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #653 from Axelrod-Python/651
651 - Tests for random seeding and a random seeding function
- Loading branch information
Showing
7 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ Contents: | |
making_tournaments.rst | ||
reading_and_writing_interactions.rst | ||
using_the_cache.rst | ||
setting_a_seed.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.. _setting_a_seed: | ||
|
||
Setting a random seed | ||
===================== | ||
|
||
The library has a variety of strategies whose behaviour is stochastic. To ensure | ||
reproducible results a random seed should be set. As both Numpy and the standard | ||
library are used for random number generation, both seeds need to be | ||
set. To do this we can use the `seed` function:: | ||
|
||
>>> import axelrod as axl | ||
>>> players = (axl.Random(), axl.MetaMixer()) # Two stochastic strategies | ||
>>> axl.seed(0) | ||
>>> axl.Match(players, turns=3).play() | ||
[('D', 'C'), ('D', 'D'), ('C', 'D')] | ||
|
||
We obtain the same results is it is played with the same seed:: | ||
|
||
>>> axl.seed(0) | ||
>>> axl.Match(players, turns=3).play() | ||
[('D', 'C'), ('D', 'D'), ('C', 'D')] | ||
|
||
Note that this is equivalent to:: | ||
|
||
>>> import numpy | ||
>>> import random | ||
>>> players = (axl.Random(), axl.MetaMixer()) | ||
>>> random.seed(0) | ||
>>> numpy.random.seed(0) | ||
>>> axl.Match(players, turns=3).play() | ||
[('D', 'C'), ('D', 'D'), ('C', 'D')] | ||
>>> numpy.random.seed(0) | ||
>>> random.seed(0) | ||
>>> axl.Match(players, turns=3).play() | ||
[('D', 'C'), ('D', 'D'), ('C', 'D')] |