>> randi_test 14-Feb-2013 13:27:35 RANDI_TEST: MATLAB version Test the MATLAB RANDI function. RANDI_TEST01: In MATLAB, random integers are generated by calling RANDI: The maximum value is specified as IMAX. A = randi ( imax, 1 ) a random scalar value between 1 and IMAX. B = randi ( imax, 5, 1 ) a random column vector of 5 entries. C = randi ( imax, 1, 5 ) a random row vector of 5 entries. D = randi ( imax, 3, 4 ) a 3 by 4 random matrix. E = randi ( imax, 5 ) a 5 by 5 random matrix. a = 9 b = 2 9 6 1 3 c = 5 9 9 2 9 d = 4 1 4 1 2 2 4 4 4 4 3 4 e = 3 1 1 1 1 4 3 4 2 2 3 1 3 2 2 2 2 2 4 3 3 1 4 4 3 RANDI_TEST02: RANDI allows the user to specify the numeric range. A = randi ( [ 5, 10 ], 1, 1 ) a random scalar value. B = randi ( [ 7, 8 ], 10, 1 ) a random column vector of 5 entries. C = randi ( [ -1, +1 ], 1, 5 ) a random row vector of 5 entries. D = randi ( [ -5, +5 ], 3, 4 ) a 3 by 4 random matrix. E = randi ( [ 100, 200 ], 5, 5 ) a 5 by 5 random matrix. a = 9 b = 7 8 8 7 7 7 8 7 8 7 c = 1 -1 0 1 1 d = 5 -4 -3 5 1 -3 3 -2 -4 4 -3 -3 e = 125 159 176 153 147 162 155 138 178 101 147 192 157 194 134 135 128 107 113 116 183 176 105 157 180 RANDI_TEST03: By setting the random number seed, you can control how the random number sequence begins. The command "rng ( 123456789 )" sets the seed to 123456789. Seed has been set to 123456789 Now generate 5 random values. RANDI([1,100],1,1) = 54 RANDI([1,100],1,1) = 54 RANDI([1,100],1,1) = 51 RANDI([1,100],1,1) = 72 RANDI([1,100],1,1) = 26 Seed has been reset to 123456789 Now generate 5 more random values. RANDI([1,100],1,1) = 54 RANDI([1,100],1,1) = 54 RANDI([1,100],1,1) = 51 RANDI([1,100],1,1) = 72 RANDI([1,100],1,1) = 26 RANDI_TEST03: By setting the random number seed, you can control how the random number sequence begins. The command "rng ( 123456789 )" sets the seed to 123456789. Seed has been set to 987654321 Now generate 5 random values. RANDI([1,100],1,1) = 8 RANDI([1,100],1,1) = 22 RANDI([1,100],1,1) = 47 RANDI([1,100],1,1) = 63 RANDI([1,100],1,1) = 62 Seed has been reset to 987654321 Now generate 5 more random values. RANDI([1,100],1,1) = 8 RANDI([1,100],1,1) = 22 RANDI([1,100],1,1) = 47 RANDI([1,100],1,1) = 63 RANDI([1,100],1,1) = 62 RANDI_TEST03: By setting the random number seed, you can control how the random number sequence begins. The command "rng ( 123456789 )" sets the seed to 123456789. Seed has been set to 123456789 Now generate 5 random values. RANDI([1,100],1,1) = 54 RANDI([1,100],1,1) = 54 RANDI([1,100],1,1) = 51 RANDI([1,100],1,1) = 72 RANDI([1,100],1,1) = 26 Seed has been reset to 123456789 Now generate 5 more random values. RANDI([1,100],1,1) = 54 RANDI([1,100],1,1) = 54 RANDI([1,100],1,1) = 51 RANDI([1,100],1,1) = 72 RANDI([1,100],1,1) = 26 RANDI_TEST: Normal end of execution. 14-Feb-2013 13:27:35 >>