[Numpy-discussion] match RNG numbers with R?

Sturla Molden sturla.molden at gmail.com
Sun Apr 6 18:53:51 EDT 2014

> a = np.random.bytes(4*n).view(dtype='<u4')

If you for example want a post-processing that just use 32 bits of
randomness per deviate, you can e.g. do something like this:

r =

I have no idea what R does, though.

NumPy's post-processing is similar to this (except without temporary

a = (np.random.bytes(4*n).view(dtype='<u4') >> 5).astype(np.int32)
b = (np.random.bytes(4*n).view(dtype='<u4') >> 6).astype(np.int32)
r = (a * 67108864.0 + b) / 9007199254740992.0


More information about the NumPy-Discussion mailing list