[Numpy-discussion] About Random Number Generation

Pauli Virtanen pav at iki.fi
Fri Oct 31 13:58:44 EDT 2008


Fri, 31 Oct 2008 10:20:41 -0700, Wu, Kejia wrote:

> Hi all,
> 
> I tried the example code here:
> http://numpy.scipy.org/numpydoc/numpy-20.html#71863 But failed:

That's the documentation of the old Numeric package, though the name of 
the URL is severly misleading.

> -------------------------------------- rng.py, line 5, in <module>
>     import RNG
> ImportError: No module named RNG
> --------------------------------------
> 
> Any suggestion? Thanks at first.

If you want to stick with the old Numeric (an obsolete software package), 
at least in Debian the random number generator is in a separate package 
(python-numeric-ext).

The random number generator available in current Numpy can be used like 
this

	import numpy.random
	data = numpy.random.rand(100, 100)

> Also, can any body tell me whether the random number algorithm in RNG
> package is a pseudorandom one or a real-random one?

Like most random number generators, it is a pseudorandom one. However, it 
seeds itself from system's random source initially.

> And is there an available implementation for Monte Carlo method in
> NumPy?

"Monte Carlo" is a generic name for a group of methods. For Monte Carlo 
Markov Chain sampling, you can eg. see PyMC [1]. I believe there are also 
other packages implementing these methods and written in Python.

.. [1] http://code.google.com/p/pymc/

-- 
Pauli Virtanen




More information about the NumPy-Discussion mailing list