Documentation Center

  • Trial Software
  • Product Updates

Contents

unifrnd

Continuous uniform random numbers

Syntax

R = unifrnd(A,B)
R = unifrnd(A,B,m,n,...)
R = unifrnd(A,B,[m,n,...])

Description

R = unifrnd(A,B) returns an array R of random numbers generated from the continuous uniform distributions with lower and upper endpoints specified by A and B, respectively. If A and B are arrays, R(i,j) is generated from the distribution specified by the corresponding elements of A and B. If either A or B is a scalar, it is expanded to the size of the other input.

R = unifrnd(A,B,m,n,...) or R = unifrnd(A,B,[m,n,...]) returns an m-by-n-by-... array. If A and B are scalars, all elements of R are generated from the same distribution. If either A or B is an array, they must be m-by-n-by-... .

Examples

Generate one random number each from the continuous uniform distributions on the intervals (0,1), (0,2), ..., (0,5):

a = 0; b = 1:5;
r1 = unifrnd(a,b)
r1 =
    0.8147    1.8116    0.3810    3.6535    3.1618

Generate five random numbers each from the same distributions:

B = repmat(b,5,1);
R = unifrnd(a,B)
R =
    0.0975    0.3152    0.4257    2.6230    3.7887
    0.2785    1.9412    1.2653    0.1428    3.7157
    0.5469    1.9143    2.7472    3.3965    1.9611
    0.9575    0.9708    2.3766    3.7360    3.2774
    0.9649    1.6006    2.8785    2.7149    0.8559

Generate five random numbers from the continuous uniform distribution on (0,2):

r2 = unifrnd(a,b(2),1,5)
r2 =
    1.4121    0.0637    0.5538    0.0923    0.1943

See Also

| | | | | |

Was this topic helpful?