summaryrefslogtreecommitdiff
path: root/numpy/random/tests/test_regression.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2012-12-15 00:31:14 +0100
committerSebastian Berg <sebastian@sipsolutions.net>2012-12-15 01:23:24 +0100
commit83d890e21ecd991976a44af040521fd800c7a175 (patch)
tree41b1c71a74e6c873428cae8db21ff80eac7a34a8 /numpy/random/tests/test_regression.py
parent4f7d3ff253888b9508f1ec06b8fea6ce1d92b502 (diff)
downloadnumpy-83d890e21ecd991976a44af040521fd800c7a175.tar.gz
BUG: internal call fix in random.choice
An random.random call from within mtrand was done by a call to np.random.random instead of inside the class. This can possibly lead to non-deterministic results after seeding.
Diffstat (limited to 'numpy/random/tests/test_regression.py')
-rw-r--r--numpy/random/tests/test_regression.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/numpy/random/tests/test_regression.py b/numpy/random/tests/test_regression.py
index 4168ef9a4..55852cc98 100644
--- a/numpy/random/tests/test_regression.py
+++ b/numpy/random/tests/test_regression.py
@@ -63,5 +63,15 @@ class TestRegression(TestCase):
random.shuffle(shuffled)
assert_array_equal(shuffled, [t[0], t[3], t[1], t[2]])
+ def test_call_within_randomstate(self):
+ # Check that custom RandomState does not call into global state
+ m = np.random.RandomState()
+ res = np.array([0, 8, 7, 2, 1, 9, 4, 7, 0, 3])
+ for i in range(3):
+ np.random.seed(i)
+ m.seed(4321)
+ # If m.state is not honored, the result will change
+ assert_array_equal(m.choice(10, size=10, p=np.ones(10.)/10), res)
+
if __name__ == "__main__":
run_module_suite()