>> randint_test 13-Feb-2013 10:45:47 RANDINT_TEST: MATLAB version Test the MATLAB RANDINT function. RANDINT_TEST01: In MATLAB, random integers are generated by calling RANDINT: If a range is not specified, the values are 0 or 1. A = randint ( ) a random scalar value. B = randint ( 5, 1 ) a random column vector of 5 entries. C = randint ( 1, 5 ) a random row vector of 5 entries. D = randint ( 3, 4 ) a 3 by 4 random matrix. E = randint ( 5 ) a 5 by 5 random matrix. a = 1 b = 1 0 1 1 1 c = 1 1 0 0 0 d = 0 1 0 1 0 1 0 0 0 1 1 0 e = 1 1 0 1 1 0 1 1 1 1 1 1 1 0 1 0 1 1 1 0 0 0 0 0 0 RANDINT_TEST02: RANDINT allows the user to specify the numeric range. A = randint ( 1, 1, [ 5, 10 ] ) a random scalar value. B = randint ( 10, 1, [ 7, 8 ] ) a random column vector of 5 entries. C = randint ( 1, 5, [ -1, +1 ] ) a random row vector of 5 entries. D = randint ( 3, 4, [ -5, +5 ] ) a 3 by 4 random matrix. E = randint ( 5, 5, [ 100, 200 ] ) a 5 by 5 random matrix. a = 9 b = 8 7 8 7 7 7 8 7 8 7 c = 0 -1 0 0 -1 d = -3 1 4 5 5 4 -2 -4 1 -4 4 -4 e = 104 198 181 182 116 158 120 117 120 125 109 117 131 115 184 121 127 147 169 182 117 127 181 171 147 RANDINT_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. RANDINT(1,1,[1,100]) = 54 RANDINT(1,1,[1,100]) = 54 RANDINT(1,1,[1,100]) = 51 RANDINT(1,1,[1,100]) = 72 RANDINT(1,1,[1,100]) = 26 Seed has been reset to 123456789 Now generate 5 more random values. RAND(1,1,[1,100]) = 54 RAND(1,1,[1,100]) = 54 RAND(1,1,[1,100]) = 51 RAND(1,1,[1,100]) = 72 RAND(1,1,[1,100]) = 26 RANDINT_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. RANDINT(1,1,[1,100]) = 8 RANDINT(1,1,[1,100]) = 22 RANDINT(1,1,[1,100]) = 47 RANDINT(1,1,[1,100]) = 63 RANDINT(1,1,[1,100]) = 62 Seed has been reset to 987654321 Now generate 5 more random values. RAND(1,1,[1,100]) = 8 RAND(1,1,[1,100]) = 22 RAND(1,1,[1,100]) = 47 RAND(1,1,[1,100]) = 63 RAND(1,1,[1,100]) = 62 RANDINT_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. RANDINT(1,1,[1,100]) = 54 RANDINT(1,1,[1,100]) = 54 RANDINT(1,1,[1,100]) = 51 RANDINT(1,1,[1,100]) = 72 RANDINT(1,1,[1,100]) = 26 Seed has been reset to 123456789 Now generate 5 more random values. RAND(1,1,[1,100]) = 54 RAND(1,1,[1,100]) = 54 RAND(1,1,[1,100]) = 51 RAND(1,1,[1,100]) = 72 RAND(1,1,[1,100]) = 26 RANDINT_TEST: Normal end of execution. 13-Feb-2013 10:45:47 >>