# rand

## Purpose

Uniformly distributed random numbers and matrices.

## Synopsis

    Y = rand(n)
    Y = rand(m,n)
    Y = rand(size(A))
    rand('seed')
    rand('seed',n)
    rand

## Description

`rand` generates random numbers and matrices whose elements are uniformly distributed in the interval (0,1).

`rand(n)` is an `n`-by-`n` matrix with random entries.

`rand(m,n)` is an `m`-by-`n` matrix with random entries.

`rand(size(A))` is the same size as `A` and has random entries.

`rand('seed')` returns the current value of the seed used by the generator.

`rand('seed',n)` sets the seed to `n`. `rand('seed',0)` sets the seed to its startup value.

`rand` with no arguments is a scalar whose value changes each time it is referenced.

The functions `rand` and `randn` maintain separate generators with separate seeds.

## Examples

If `rand` has not yet been used during a particular MATLAB session, then `R = rand(3,4)` produces

     R =
        0.2190    0.6793    0.5194    0.0535
        0.0470    0.9347    0.8310    0.5297
        0.6789    0.3835    0.0346    0.6711

A random choice between two equally probable alternatives can be made with

     if rand < .5
        'heads'
     else
        'tails'
     end

## Algorithm

`rand` is a uniform random number generator based on the linear congruential method described in [1]. The basic algorithm is

## See Also

    randn, randperm

## Reference

[1]Park, S.K. and K.W. Miller, "Random Number Generators: Good ones are hard to find," Comm. A.C.M., vol. 31, n. 10, pgs. 1192-1201, Oct. 1988.

(c) Copyright 1994 by The MathWorks, Inc.