diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/random.py | 3 | ||||
-rw-r--r-- | Lib/test/test_random.py | 7 |
2 files changed, 10 insertions, 0 deletions
diff --git a/Lib/random.py b/Lib/random.py index 1ae2553..1a0b8f3 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -123,6 +123,9 @@ class Random(_random.Random): def __setstate__(self, state): # for pickle self.setstate(state) + def __reduce__(self): + return self.__class__, (), self.getstate() + ## -------------------- integer methods ------------------- def randrange(self, start, stop=None, step=1, int=int, default=None): diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py index 970b862..ea2243d 100644 --- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -3,6 +3,7 @@ import unittest import random import time +import pickle from math import log, exp, sqrt, pi from sets import Set from test import test_support @@ -102,6 +103,12 @@ class TestBasicOps(unittest.TestCase): self.assertEqual(x1, x2) self.assertEqual(y1, y2) + def test_pickling(self): + state = pickle.dumps(self.gen) + origseq = [self.gen.random() for i in xrange(10)] + newgen = pickle.loads(state) + restoredseq = [newgen.random() for i in xrange(10)] + self.assertEqual(origseq, restoredseq) class WichmannHill_TestBasicOps(TestBasicOps): gen = random.WichmannHill() |