Statistics Toolbox | ![]() ![]() |
Syntax for Random Number Functions. You can generate random numbers from each distribution. This function provides a single random number or a matrix of random numbers, depending on the arguments you specify in the function call.
For example, here is the way to generate random numbers from the beta distribution. Four statements obtain random numbers: the first returns a single number, the second returns a 2-by-2 matrix of random numbers, and the third and fourth return 2-by-3 matrices of random numbers.
a = 1; b = 2; c = [.1 .5; 1 2]; d = [.25 .75; 5 10]; m = [2 3]; nrow = 2; ncol = 3; r1 = betarnd(a,b) r1 = 0.4469 r2 = betarnd(c,d) r2 = 0.8931 0.4832 0.1316 0.2403 r3 = betarnd(a,b,m) r3 = 0.4196 0.6078 0.1392 0.0410 0.0723 0.0782 r4 = betarnd(a,b,nrow,ncol) r4 = 0.0520 0.3975 0.1284 0.3891 0.1848 0.5186
![]() | Random Number Generator | Mean and Variance as a Function of Parameters | ![]() |