\section{RAND Uniform Random Number Generator}

\subsection{Usage}

Creates an array of pseudo-random numbers of the specified size.
The numbers are uniformly distributed on \verb|[0,1)|.  
Two seperate syntaxes are possible.  The first syntax specifies the array 
dimensions as a sequence of scalar dimensions:
\begin{verbatim}
  y = rand(d1,d2,...,dn).
\end{verbatim}
The resulting array has the given dimensions, and is filled with
random numbers.  The type of \verb|y| is \verb|double|, a 64-bit floating
point array.  To get arrays of other types, use the typecast 
functions.
    
The second syntax specifies the array dimensions as a vector,
where each element in the vector specifies a dimension length:
\begin{verbatim}
  y = rand([d1,d2,...,dn]).
\end{verbatim}
This syntax is more convenient for calling \verb|rand| using a 
variable for the argument.

Finally, \verb|rand| supports two additional forms that allow
you to manipulate the state of the random number generator.
The first retrieves the state
\begin{verbatim}
  y = rand('state')
\end{verbatim}
which is a 625 length integer vector.  The second form sets
the state
\begin{verbatim}
  rand('state',y)
\end{verbatim}
or alternately, you can reset the random number generator with
\begin{verbatim}
  rand('state',0)
\end{verbatim}
\subsection{Example}

The following example demonstrates an example of using the first form of the \verb|rand| function.
\begin{verbatim}
--> rand(2,2,2)

ans = 

(:,:,1) = 

    0.3478    0.5313 
    0.0276    0.9958 

(:,:,2) = 

    0.2079    0.7597 
    0.4921    0.3365 


\end{verbatim}
The second example demonstrates the second form of the \verb|rand| function.
\begin{verbatim}
--> rand([2,2,2])

ans = 

(:,:,1) = 

    0.8670    0.2174 
    0.2714    0.6897 

(:,:,2) = 

    0.2305    0.3898 
    0.1721    0.9545 


\end{verbatim}
The third example computes the mean and variance of a large number of uniform random numbers.  Recall that the mean should be \verb|1/2|, and the variance should be \verb|1/12 ~ 0.083|.
\begin{verbatim}
--> x = rand(1,10000);
--> mean(x)

ans = 

    0.5023 

--> var(x)

ans = 

 8.3981e-02 


\end{verbatim}
Now, we use the state manipulation functions of \verb|rand| to exactly reproduce 
a random sequence.  Note that unlike using \verb|seed|, we can exactly control where
the random number generator starts by saving the state.
\begin{verbatim}
--> rand('state',0)    % restores us to startup conditions
--> a = rand(1,3)      % random sequence 1

a = 

    0.3759    0.0183    0.9134 

--> b = rand('state'); % capture the state vector
--> c = rand(1,3)      % random sequence 2  

c = 

    0.3580    0.7604    0.8077 

--> rand('state',b);   % restart the random generator so...
--> c = rand(1,3)      % we get random sequence 2 again

c = 

    0.3580    0.7604    0.8077 


\end{verbatim}
