[Numpy-discussion] random.RandomState and deepcopy

Robert Kern robert.kern at gmail.com
Fri Mar 13 13:45:03 EDT 2015

On Fri, Mar 13, 2015 at 5:34 PM, Neal Becker <ndbecker2 at gmail.com> wrote:
> It is common that to guarantee good statistical independence between
> random generators, a singleton instance of an RNG is shared between them.
> So I typically have various random generator objects, which (sometimes
> several levels objects deep) embed an instance of RandomState.
> Now I have a requirement to copy a generator object (without knowing
> what that generator object is).

Or rather, you want the generator object to *avoid* copies by returning
itself when a copy is requested of it.

> My solution is to use deepcopy on the top-level object.  But I need to
> overload __deepcopy__ on the singleton RandomState object.
> Unfortunately, RandomState doesn't allow customization of __deepcopy__ (or
> anything else).  And it has no __dict__.

You can always subclass RandomState to override its __deepcopy__.

Robert Kern
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150313/5f3bb76f/attachment.html>

More information about the NumPy-Discussion mailing list