Package pype :: Module prand :: Class MTRandom
[frames] | no frames]

Class MTRandom

source code

object --+
         |
        MTRandom

Instance Methods
 
__init__(self, seed=None, state=None)
Uniform random number generator object.
source code
 
getstate(self)
Get signed/unsigned state vector for current generator state.
source code
 
setstate(self, state)
Restore generator to saved state.
source code
 
rand(self, count=None)
Generate random numbers.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self, seed=None, state=None)
(Constructor)

source code 

Uniform random number generator object.

Instantiate a uniform random number generator. This should be the Mersenne Twister based generator that is standard in Python (at least up to version 2.6).

Generates floating point numbers in the range [0-1].

If neither seed nor state are supplied, this will use the current time to generate a seed.

NB To set the matlab random number generator to the same known state as the python generator, you need to convert the signed values of the seed into unsigned values as follows:

>> seed = [get me from file etc..]; >> seed(seed < 0 ) = seed(seed < 0) + (2^32); >> rand('twister', seed);
Parameters:
  • seed - (int) single integer seed value
  • state - (int array) length 624 SIGNED 2-byte integer vector that completely captures the state of the random number generator. Note that these are SIGNED values -- matlab expects UNSIGNED values; see notes below. This comes from .getstate() method below
Overrides: object.__init__

getstate(self)

source code 
Get signed/unsigned state vector for current generator state.
Returns:
(array) state vector

setstate(self, state)

source code 
Restore generator to saved state.
Parameters:
  • state - (array) state vector from getstate()
Returns:
nothing

rand(self, count=None)

source code 

Generate random numbers.

With no arguments generates a single floating point random number on the range [0-1]. If count is specified, then returns a list of count random numbers.

Parameters:
  • count - (None or int) if not None, number of numbers to generate
Returns:
(float) random floats on range [0-1]