2009/9/10 Hans Georg Schaathun <ge...@ii.uib.no>: > 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 > -- > http://mail.python.org/mailman/listinfo/python-list >
Hi, I didn't tested the specifications nor the efficiency anywhere near your requirements, but maybe some suggestions to try anyway. mpmath http://code.google.com/p/mpmath/ and gmpy http://code.google.com/p/gmpy/ both have the rand function, the latter likely faster and more customizable; cf. the help text : """ Help on built-in function rand in module gmpy: rand(...) rand(opt[,arg]): expose various GMP random-number operations, depending on value of parameter 'opt' (a string) -- arg is normally an int or mpz (or else gets coerced to mpz), but must be a Python mutable sequence when opt is 'shuf': 'init': initialize random-state to support arg bits of 'good randomness', for arg between 1 and 128 (default 32). May be called again to change this 'random-quality'. 'qual': returns the number-of-bits-of-good-randomness (0 if the random-generator not yet initialized), arg ignored. 'seed': set/reset random-state's seed to arg. 'save': get random-state seed (for saving) - arg is ignored. 'next': get random mpz, 0 (included) to arg (excluded) (default range is 0..2**31). 'floa': get random mpf, range 0<=x<1, with arg meaningful bits (default, if arg missing or 0, is current 'random quality'). 'shuf': random shuffle of Python list (or other mutable sequence) 'arg'; shuffle is in-place, None returned. """ hth vbr -- http://mail.python.org/mailman/listinfo/python-list