www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/RandomIntegersUGExample.m
%% Random Integers % %% Section 1 % The simplest |randi| syntax returns double-precision integer values % between 1 and a specified value, |imax|. To specify a different range, % use the |imin| and |imax| arguments together. %% % First, initialize the random number generator to make the results in this % example repeatable. rng(0,'twister'); %% % Create a 1-by-1000 array of random integer values drawn from a discrete % uniform distribution on the set of numbers -10, -9,...,9, 10. Use the % syntax, |randi([imin imax],m,n)|. r = randi([-10 10],1,1000); %% % Verify that the values in |r| are within the specified range. r_range = [min(r) max(r)]