This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients mark.dickinson, pitrou, rhettinger, serhiy.storchaka, tim.peters, vstinner
Date 2020-04-24.16:19:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1587745176.1.0.613237396222.issue40346@roundup.psfhosted.org>
In-reply-to
Content
Antoine:
> However, if we want to think about a new subclassing API, it may be worth looking at the recent Numpy changes. Numpy added a new random generator API recently, with a design based on composition rather than inheritance (and also they switched from Mersenne Twister to another underlying PRNG!):
> https://numpy.org/doc/stable/reference/random/index.html

Yeah, sometimes composition is simpler. My BaseRandom base class (PR 19631) can be used with composition indirectly, since all you need is to implemented getrandbits(). Example:

---
from numpy.random import default_rng
import random

class NumpyRandom(random.BaseRandom):
    def __init__(self):
        self._rng = default_rng()

    def getrandbits(self, n):
        # FIXME: support n larger than 64 ;-)
        return int(self._rng.integers(2 ** n))

gen = NumpyRandom()
print(gen.randint(1, 6))
print(gen.random())
print(gen.randbytes(3))
---
History
Date User Action Args
2020-04-24 16:19:36vstinnersetrecipients: + vstinner, tim.peters, rhettinger, mark.dickinson, pitrou, serhiy.storchaka
2020-04-24 16:19:36vstinnersetmessageid: <1587745176.1.0.613237396222.issue40346@roundup.psfhosted.org>
2020-04-24 16:19:36vstinnerlinkissue40346 messages
2020-04-24 16:19:35vstinnercreate