Preferred Random Library
robert.kern at gmail.com
Thu Apr 26 07:56:50 CEST 2007
Bill Jackson wrote:
> Is there a preferred random library?
> Besides scipy's library returning ndarrays, is there any other
numpy.random (since that's where scipy.random comes from, I recommend always
referring to it as numpy.random) can be a bit faster since it is implemented as
entirely an extension module; parts of random are implemented in Python and
incur Python function call overhead. It's certainly faster if you need a lot of
numbers at once. numpy.random has several more non-uniform distributions
numpy.random does not implement jumpahead(). random, naturally, does not require
a third-party package.
By and large, I'd say the distinguishing factor is whether or not you want to
use numpy in your program. If so, then use numpy.random. If not, then use random.
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list