question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extending RandomState to handle multiple generators

See original GitHub issue

I have been working on a more general implementation of RandomState that allow multiple RNGs to be implemented. The repo is here

Currently it passes the NumPy test suite for mt19937 as well as another direct comparrison.

The library consists of a few layers:

  1. The source for the RNG
  2. A shim library that provides a few core RNGs - uint 32/64 and double
  3. A shared set of C/pyx code that use definitions and Cython conditional compilation

Ultimately this will generate libraries for any include random number where each library contains the same RandomState class that is in Numpy. Currently the following RNGs are available (on Linux and other unix-like OSes + Windows Py 3.5)

  • mt19937 (identical to the NumPy implementation)
  • xorshift128+ and xorshift1024*
  • pcg-32 and pcg-64
  • mrg32k3a (popular but slow, not sure it should be included in any final version)
  • A basic MLFG

It is pretty easy to add new core RNGs.

In addition, it supports jump and advance for RNGs that have these capabilities, which makes it suitable for use in parallel applications.

Still has a way to go, especially for Windows 2.7/3.4 support, but seems close enough to start talking about and getting feedback.

xref #2039

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:9
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
bashtagecommented, Apr 11, 2019

xref #13163 . This is fixed in the randomgen branch.

1reaction
shoyercommented, May 18, 2016

@bashtage This is kind of a dumb question, but could you please clarify for me the difference between jumping and advancing an RNG?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Initiate different random number generators from the same ...
With the new BitGenerator package, you can create mulitple generators from the same seed, rd0 = np.random.default_rng(seed) (using PCG64). – ...
Read more >
MT19937 Randomstate
This allows the original sequence to be split so that distinct segments can be used in each worker process. All generators should be...
Read more >
Best way to seed N independent random number generators ...
Currently I use numpy 's RandomState which uses a Mersenne Twister pseudo-random number generator. Snippet of code below: # If a random number ......
Read more >
randomstate - PyPI
Next-gen RandomState supporting multiple PRNGs. ... This is a library and generic interface for alternative random generators in Python and NumPy.
Read more >
Random sampling (`numpy.random`)
Since Numpy version 1.17.0 the Generator can be initialized with a number of different BitGenerators. It exposes many different probability ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found