Generates random data from the uniform probability distribution. There are two forms. |
||
Syntax |
RND = UnifRnd(a, b, Rows, Cols, Seed, State) RND = UnifRnd(a, b, Seed, State) |
|
Arguments |
Name |
Description |
a (optional) |
Lower end point of the distribution. A scalar, vector or matrix. |
|
b (optional) |
Upper end point of the distribution. A scalar, vector or matrix. |
|
Rows (optional) |
Number of output rows. A positive integer. Only valid when a and b are scalars. |
|
Cols (optional) |
Number of output columns. A positive integer. Only valid when a and b are scalars. |
|
Seed (optional) |
The seed to initialize the random number generator. See Comments below. |
|
State (optional) |
Set to "discard" if the state of the pseudo random number is not to be retained for future use. The default is "retain". |
|
Output |
Name |
Description |
|
RND |
Random numbers from the continuous uniform distribution. Its size is determined by the input arguments. See Comments below. |
Example 1 |
Generate two random numbers from continuous uniform distribution with lower and upper limit pairs of (0, 2) and (-1, 1), respectively: |
|
|
Syntax |
|
|
rnd = UnifRnd([0,-1],[2,1]) |
|
|
Result |
|
|
rnd = 0.4053 0.3443 |
|
Example 2 |
Generate a 1x4 vector of random numbers from a continuous uniform distribution within the interval (-1, 1): |
|
|
Syntax |
|
|
rnd = UnifRnd(-1,1,1,4) |
|
|
Result |
|
|
rnd = 0.6762 -0.9607 0.3626 -0.2410 |
|
Comments |
a and b must be the same size. If a and b are both omitted then a = 0 and b = 1. If the optional size inputs are omitted, the size of the output is solely determined by the size of the two inputs a and b. Each entry in the output uses the corresponding entries in the two inputs. If the optional size inputs are provided, both must be supplied. In that case a and b must be scalars and the size of the output is determined by Rows and Cols. That is, the inputs a and b are used for each element of the output. The Seed can be any number. Using a seed allows a random sequence to be repeated. |
|
See Also: |