>> rand_test 11-Jun-2012 15:58:51 RAND_TEST: MATLAB version Test the MATLAB RAND function. RAND_TEST01: In MATLAB, unit random numbers are generated by calling RAND: A = rand ( ) a random scalar value. B = rand ( 5, 1 ) a random column vector of 5 entries. C = rand ( 1, 5 ) a random row vector of 5 entries. D = rand ( 3, 4 ) a 3 by 4 random matrix. E = rand ( 5 ) a 5 by 5 random matrix. a = 0.1954 b = 0.5357 0.0070 0.5555 0.0882 0.9447 c = 0.1037 0.3044 0.4321 0.0960 0.8795 d = 0.4961 0.4842 0.8362 0.1146 0.9611 0.4599 0.4767 0.3620 0.8500 0.8635 0.8786 0.6463 e = 0.8118 0.8585 0.8465 0.0997 0.3893 0.9436 0.3477 0.9979 0.9614 0.9230 0.9043 0.0182 0.7316 0.2513 0.5029 0.3433 0.1560 0.5484 0.4184 0.3784 0.0642 0.5856 0.5977 0.9359 0.6705 RAND_TEST02: 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. RAND() = 0.532833 RAND() = 0.534137 RAND() = 0.509553 RAND() = 0.713564 RAND() = 0.256999 Seed has been reset to 123456789 Now generate 5 more random values. RAND() = 0.532833 RAND() = 0.534137 RAND() = 0.509553 RAND() = 0.713564 RAND() = 0.256999 RAND_TEST02: 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. RAND() = 0.532833 RAND() = 0.534137 RAND() = 0.509553 RAND() = 0.713564 RAND() = 0.256999 Seed has been reset to 123456789 Now generate 5 more random values. RAND() = 0.532833 RAND() = 0.534137 RAND() = 0.509553 RAND() = 0.713564 RAND() = 0.256999 RAND_TEST02: 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. RAND() = 0.532833 RAND() = 0.534137 RAND() = 0.509553 RAND() = 0.713564 RAND() = 0.256999 Seed has been reset to 123456789 Now generate 5 more random values. RAND() = 0.532833 RAND() = 0.534137 RAND() = 0.509553 RAND() = 0.713564 RAND() = 0.256999 RAND_TEST03: Compute a lot of random values. The average should be 0.5 The variance should be 1/12. N Ave Ave-1/2 Var Var-1/12 1 0.752694 2.53e-01 0.000000 -8.33e-02 10 0.497594 -2.41e-03 0.112223 2.89e-02 100 0.501658 1.66e-03 0.085044 1.71e-03 1000 0.499868 -1.32e-04 0.083581 2.48e-04 10000 0.503508 3.51e-03 0.083392 5.89e-05 100000 0.499446 -5.54e-04 0.083799 4.66e-04 1000000 0.499723 -2.77e-04 0.083307 -2.65e-05 10000000 0.499979 -2.12e-05 0.083323 -1.02e-05 RAND_TEST: Normal end of execution. 11-Jun-2012 15:58:52 >>