[Numpy-discussion] Moving NumPy's PRNG Forward

Neal Becker ndbecker2 at gmail.com
Sat Jan 20 07:19:59 EST 2018

On Fri, Jan 19, 2018 at 6:13 PM Nathaniel Smith <njs at pobox.com> wrote:

> ...

> I agree that relaxing our policy would be better than the status quo.
> Before making any decisions, though, I'd like to make sure we
> understand the alternatives and their trade-offs. Specifically, I
> think the main alternative would be the following approach to
> versioning:
> 1) make RandomState's state be a tuple (underlying RNG algorithm,
> underlying RNG state, distribution version)
> 2) zero-argument initialization/seeding, like RandomState() or
> rstate.seed(), sets the state to: (our recommended RNG algorithm,
> os.urandom(...), version=LATEST_VERSION)
> 3) for backcompat, single-argument seeding like RandomState(123) or
> rstate.seed(123), sets the state to: (mersenne twister,
> expand_mt_seed(123), version=0)
> 4) also allow seeding to explicitly control all the parameters, like
> RandomState(PCG_XSL_RR(123), version=12) or whatever
> 5) the distribution functions are implemented like:
> def normal(*args, **kwargs):
>     if self.version < 3:
>         return self._normal_box_muller(*args, **kwargs)
>     elif self.version < 8:
>         return self._normal_ziggurat_v1(*args, **kwargs)
>     else:  # version >= 8
>         return self._normal_ziggurat_v2(*args, **kwargs)

I like this suggestion, but I suggest to modify it so that a zero-argument
initialization or 1-argument seeding will initialize to a global value,
which would  default to backcompat, but could be changed.  Then my old code
would by default produce the same old results, but adding 1 line at the top
switches to faster code if I want.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20180120/10599b54/attachment.html>

More information about the NumPy-Discussion mailing list