On Sat, Aug 19, 2023 at 10:49 AM Kevin Sheppard <kevin.k.sheppard@gmail.com> wrote:
The easiest way to do this would to to write a pure python implementation using Python ints of a masked integer sampler.  This way you could draw unsigned integers and then treat this as a bit pool.  You would than take the number of bits needed for your integer, transform these to be a Python int, and finally apply the mask.  

Indeed, that's how `random.Random` does it. I've commented on the issue with an implementation that subclasses `random.Random` to use numpy PRNGs as the source of bits for maximum compatibility with `Random`. The given use case motivating this feature request is networkx, which manually wraps numpy PRNGs in a class that incompletely mimics the `Random` interface. A true subclass eliminates all of the remaining inconsistencies between the two. I'm inclined to leave it at that and not extend the `Generator` interface.

https://github.com/numpy/numpy/issues/24458#issuecomment-1685022258

--
Robert Kern