altroware
altroware

Reputation: 980

How do I share the random number generator in numpy c-api?

I wrote a Python program for Monte Carlo simulations that calls numpy functions that makes use of the built-in random number generator (e.g., np.random.normal() or np.random.choice()) and also imports some c++ functions (compiled using the standard numpy c-api) which also make use of a random number generator.

However, in order to be statistically correct, I need that both the numpy and numpy c-api functions use the same random number generator.

I presume I should pass the python random number generator to the c-api functions, or vice-versa.

How can I make sure that all the functions use the same pseudo random number generator?

Upvotes: 1

Views: 286

Answers (1)

LurkerZ
LurkerZ

Reputation: 98

Old question but currently there is a working example in the documentation of numpy for extending the random distributions. It shows how to reuse a generator in the examples . I hope this helps.

Upvotes: 1

Related Questions