Learn R Programming

pracma (version 0.7.5)

rand: Create Random Matrices

Description

Create random matrices.

Usage

rand(n = 1, m = n)
randn(n = 1, m = n)
randi(imax, n = 1, m = n)

Arguments

n, m
integers specifying the size of the matrix
imax
integer or pair of integers

Value

  • matrices of size n x m resp. a vector of length n

Details

rand(), randn(), randi() create random matrices of size n x m, where the default is square matrices if m is missing.

rand() uses the uniform distribution on ]0, 1[, while randn() uses the normal distribution with mean 0 and standard deviation 1.

randi() generates integers between imax[1] and imax[2] resp. 1 and imax, if imax is a scalar.

See Also

set.seed

Examples

Run this code
rand(3)
randn(1, 5)
randi(c(1,6), 1, 10)

Run the code above in your browser using DataLab