numpy C-API :: use numpy's random number generator in a ufunc
![](https://secure.gravatar.com/avatar/276272306b15b19547cd916dfb2dd5f0.jpg?s=120&d=mm&r=g)
Hi folks, I currently have a project that requires randomness in a ufunc. In order to keep the ufuncs as reproducible as possible I would like to use numpy's random number generator for that; basically because setting the seed will be more intuitive this way. However I cannot find the documentation of the numpy.random C-API (does it have one?). How would one do that? Cheers, -- Daniel Knüttel <daniel.knuettel@daknuett.eu>
![](https://secure.gravatar.com/avatar/72f994ca072df3a3d2c3db8a137790fd.jpg?s=120&d=mm&r=g)
Hi Daniel. Usually one would use python, something like `rng = np.random.Generator(np.random.PCG64(seed)); a = rng.uniform(10, size=(3, 4))` to get a 3 by 4 array of uniform random numbers in the range of 0 to 10. Is there a reason you need to do this from C? Matti -- Sent from: http://numpy-discussion.10968.n7.nabble.com/
![](https://secure.gravatar.com/avatar/72f994ca072df3a3d2c3db8a137790fd.jpg?s=120&d=mm&r=g)
Hi Daniel. Usually one would use python, something like `rng = np.random.Generator(np.random.PCG64(seed)); a = rng.uniform(10, size=(3, 4))` to get a 3 by 4 array of uniform random numbers in the range of 0 to 10. Is there a reason you need to do this from C? Matti -- Sent from: http://numpy-discussion.10968.n7.nabble.com/
participants (2)
-
Daniel Knüttel
-
mattip