2.8 Randomly Generated Matrices

The cvxopt module provides two functions normal() and uniform() for generating randomly distributed matrices. The default installation relies on the pseudo-random number generators in the Python standard library random. Alternatively, the random number generators in the GNU Scientific Library (GSL) can be used, if this option is selected during the installation of CVXOPT. The random matrix functions based on GSL are faster than the default functions based on the random module.

normal(nrows[, ncols[, mean[, std]]])

Returns a type ’d’ dense matrix of size nrows by ncols with elements chosen from a normal distribution with mean mean and standard deviation std. The default values for the optional arguments are ncols=1, mean=0.0, std=1.0.

uniform(nrows[, ncols[, a[, b]]])

Returns a type ’d’ dense matrix of size nrows by ncols matrix with elements uniformly distributed between a and b. The default values for the optional arguments are ncols=1, a=0.0, b=1.0.

setseed([value])

Sets the state of the random number generator. value must be an integer. If value is absent or equal to zero, the value is taken from the system clock. If the Python random number generators are used, this is equivalent to random.seed(value).

getseed()

Returns the current state of the random number generator. This function is only available if the GSL random number generators are installed. (The state of the random number generators in the Python random module can be managed via the functions random.getstate() and random.setstate().)