Uniform random numbers
R = distfun_unifrnd ( a , b ) R = distfun_unifrnd ( a , b , [m,n] ) R = distfun_unifrnd ( a , b , m , n )
a n-by-m matrix of doubles, the lower bound
a n-by-m matrix of doubles, the upper bound (with a<=b)
a 1x1 matrix of floating point integers, the number of rows of R
a 1x1 matrix of floating point integers, the number of columns of R
a matrix of doubles, the random numbers in the interval [a,b].
Generates random variablesfrom the Uniform distribution function.
Any scalar input argument is expanded to a matrix of doubles of the same size as the other input arguments.
// Set the seed so as to always get the same results. distfun_seedset(1); // Use R = distfun_unifrnd ( a , b ) distfun_unifrnd(1:6,2:7) distfun_unifrnd(1:6,7) distfun_unifrnd(1,2:7) // Check mean and variance for R = distfun_unifrnd ( a , b ) N = 1000; a = 1:6; b = 2:7; m = (a+b)/2; // Expectation v = (b-a).^2/12.; // Variance for i = 1:N computed(i,1:6) = distfun_unifrnd(a,b); end c = mean(computed(1:N,1:6) , "r" ) disp(m) c = st_deviation(computed(1:N,1:6) , "r" ) e = sqrt(v) // Check R = distfun_unifrnd ( a , b , v ) computed = distfun_unifrnd(2,3,[1 5]) computed = distfun_unifrnd(2,3,[3 2]) // Check mean and variance for R = distfun_unifrnd ( a , b ) N = 1000; a = 2; b = 3; m = (a+b)/2; // Expectation v = (b-a).^2/12.; // Variance computed = distfun_unifrnd(2,3,[1 N]); c = mean(computed(1:N) ) disp(m) c = st_deviation(computed(1:N) ) e = sqrt(v) // Check R = distfun_unifrnd ( a , b , m , n ) computed = distfun_unifrnd([1 2 3;4 5 6],7,2,3) computed = distfun_unifrnd(4,5,2,3) computed = distfun_unifrnd(0,[1 2 3;4 5 6],2,3) // Check mean and variance for R = distfun_unifrnd ( a , b ) N = 1000; a = 2; b = 3; m = a .* b; // Expectation v = m .* b; // Variance computed = distfun_unifrnd(a,b,1,N); c = mean(computed(1:N) ) disp(m) c = st_deviation(computed(1:N) ) e = sqrt(v) // Make a plot of the actual distribution of the numbers a = 2; b = 3; data = distfun_unifrnd(a,b,1,1000); scf(); histplot(10,data) x = linspace(a-1,b+1,1000); y = distfun_unifpdf(x,a,b); plot(x,y) xtitle("Uniform random numbers","X","Density"); legend(["Empirical","PDF"]); | ![]() | ![]() |