Instatiable Pseudo-Random Number Generator

  • Thread starter Hans Georg Schaathun
  • Start date
H

Hans Georg Schaathun

I wonder if someone knows of an API with the features I need...
random.Random and numpy.random each have only half of it...

My application includes an object to hold a pseudo-randomly
generated matrix too large to be kept in memory. Hence I
try to store only the seed, and generate the numbers on the fly.

This can be done by giving the object an instance of random.Random.
As far as I can see, numpy.random has a global state, and thus
cannot be used by several concurrent random-matrix objects.

My problem is that random.Random is much slower than numpy.random.
(Three times slower in a small test.) I believe this is because
numpy.random can return a row at a time, while random.Random only
return scalars (as far as I have seen).

Can anyone recommend a PRNG which supported multiple instances
with independent states, and that also can return numpy.array (or
something similar) efficiently?

The distribution is currently Gaussian.

Thanks in advance,
:-- George
 
S

sturlamolden

Can anyone recommend a PRNG which supported multiple instances
with independent states, and that also can return numpy.array (or
something similar) efficiently?

numpy.random.RandomState

;-)

S.M.
 
J

Joachim Strömbergson

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Aloha!
Can anyone recommend a PRNG which supported multiple instances
with independent states, and that also can return numpy.array (or
something similar) efficiently?

The distribution is currently Gaussian.

Do the PRNG need to support Gaussian directly, or can you live with a
good uniform distribution? If uniform is ok then any good stream cipher
implementation should do the trick. Or a block cipher in a stream cipher
mode, for example AES in CTR mode.

If you need a pure Python implementation I have one such implementation
of the Snow stream cipher:

http://www.strombergson.com/files/snow.py.gz
http://en.wikipedia.org/wiki/SNOW

You can instantiate as many Snow objects as you need, each with their
own state. On my laptop I get about 300 kByte/s, is that too slow for
your application?

- --
Med vänlig hälsning, Yours

Joachim Strömbergson - Alltid i harmonisk svängning.
========================================================================
Kryptoblog - IT-säkerhet på svenska
http://www.strombergson.com/kryptoblog
========================================================================
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkqo5PsACgkQZoPr8HT30QGQZgCgp3FcOJ1VbP03kGIMFVTkZgHb
el0AoO5bavQCfeyXX5RFlb7dVvWBOl2O
=s0eq
-----END PGP SIGNATURE-----
 
H

Hans Georg Schaathun

: > Can anyone recommend a PRNG which supported multiple instances
: > with independent states, and that also can return numpy.array (or
: > something similar) efficiently?
:
: numpy.random.RandomState

Thanks. Perfect solution.

I wish the doc string of numpy.random had mentioned it :)

:-- George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top