Producing random matrices: randmatrix ranm randMat

### 8.3.16 Producing random matrices: randmatrix ranm randMat

The randmatrix command produces random vectors and matrices. (See also Section 5.27.28 and Section 8.3.15.)
ranm and randMat are synonyms for randmatrix.

- randmatrix takes one mandatory argument and three optional arguments:
  - n, an integer.
  - Optionally, p, an integer.
  - Optionally, a, an integer.
  - Optionally, a..b, a range.
  - Optionally, distr, a distribution, which can be one of:
    - ’rand(n)’ (see Section 8.3.1).
    - ’binomial(n,p)’, ’binomial,n,p’ or ’randbinomial(n,p)’, for a binomial distribution (see Section 8.4.3 and Section 8.3.3).
    - ’multinomial(P,K)’, ’multinomial,P,K’ or ’randmultinomial(P,K)’ for a multinomial distribution (see Section 8.4.5 and Section 8.3.4).
    - ’poisson(λ)’, ’poisson, λ’ or ’randpoisson(λ)’ for a Poisson distribution (see Section 8.4.6 and Section 8.3.5).
    - ’normald(µ,σ)’, ’normald,µ,σ’ or ’randnorm(µ,σ)’ for a normal distribution (see Section 8.4.7 and Section 8.3.6).
    - ’exp(a)’, ’exp,a’ or ’randexp(a)’ for an exponential distribution (see Section 8.4.15 and Section 8.3.13).
    - ’fisher(n,m)’, ’fisher,n,m’ or ’randfisher(n,m)’ for a Fisher-Snédécor distribution (see Section 8.4.10 and Section 8.3.9).
    Note that distr is in quotes.
- randmatrix(n) returns a vector of length n whose elements are integers chosen randomly from [−99,−98,…,98,99] with equal probability.
- randmatrix(n,p) returns an n× p matrix whose elements are integers chosen randomly from [−99,99] with equal probability.
- randmatrix(n,p,a) returns an n× p matrix whose elements are integers chosen randomly from [0,a) (or (a,0] is a is negative) with equal probability.
- randmatrix(n,p,a..b) returns an n× p matrix whose elements are real numbers chosen randomly from [a,b) with equal probability.
- randmatrix(n,p,distr) returns an n× p matrix whose elements are numbers chosen randomly according to distribution distr.

#### Examples

- Input:
  randmatrix(5)
  Output (for example):

  ⎡ ⎣ | −48,54,28,−51,63 | ⎤ ⎦

- Input:
  randmatrix(2,3)
  Output (for example):

  ⎛ ⎜ ⎝ |
  40 | −74 | −87
  40 | −19 | 20
  | ⎞ ⎟ ⎠

- Input:
  randmatrix(2,3,10)
  Output (for example):

  ⎛ ⎜ ⎝ |
  4 | 2 | 1
  4 | 4 | 0
  | ⎞ ⎟ ⎠

- Input:
  randmatrix(2,3,0..1)
  Output (for example):

  ⎛ ⎜ ⎝ |
  0.384355471935 | 0.655490326229 | 0.924850208685
  0.159429819323 | 0.952957109548 | 0.220945354551
  | ⎞ ⎟ ⎠

- Input:
  randmatrix(2,3,’randnorm(2,1)’)
  Output (for example):

  ⎛ ⎜ ⎝ |
  2.17670501195 | 0.653882567048 | 2.94543112983
  2.46150672679 | 2.19251320854 | 2.44211638655
  | ⎞ ⎟ ⎠