This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

rand (RandStream)

Uniformly distributed random numbers


r = rand(s,n)
r = rand(s,m,n)
r = rand(s,[m,n])
r = rand(s,m,n,p,...)
r = rand(s,[m,n,p,...])
r = rand(s)
r = rand(s,size(A))
r = rand(..., 'double')
r = rand(..., 'single')


r = rand(s,n) returns an n-by-n matrix containing pseudorandom values drawn from the standard uniform distribution on the open interval (0,1). The values are drawn from the random stream s.

r = rand(s,m,n) or r = rand(s,[m,n]) returns an m-by-n matrix.

r = rand(s,m,n,p,...) or r = rand(s,[m,n,p,...]) returns an m-by-n-by-p-by-... array.

r = rand(s) returns a scalar.

r = rand(s,size(A)) returns an array the same size as A.

r = rand(..., 'double') or r = rand(..., 'single') returns an array of uniform values of the specified class.


The size inputs m, n, p, ... should be nonnegative integers. Negative integers are treated as 0.

The sequence of numbers produced by rand is determined by the internal state of the random number stream s. Resetting that stream to the same fixed state allows computations to be repeated. Setting the stream to different states leads to unique computations, however, it does not improve any statistical properties.

Was this topic helpful?