07-Jan-2022 23:01:09 matlab_random_test(): MATLAB/Octave version 9.8.0.1380330 (R2020a) Update 2 Test MATLAB random number generators. 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.8147 b = 0.9058 0.1270 0.9134 0.6324 0.0975 c = 0.2785 0.5469 0.9575 0.9649 0.1576 d = 0.9706 0.8003 0.9157 0.6557 0.9572 0.1419 0.7922 0.0357 0.4854 0.4218 0.9595 0.8491 e = 0.9340 0.6555 0.0462 0.9502 0.7952 0.6787 0.1712 0.0971 0.0344 0.1869 0.7577 0.7060 0.8235 0.4387 0.4898 0.7431 0.0318 0.6948 0.3816 0.4456 0.3922 0.2769 0.3171 0.7655 0.6463 RAND_TEST02: By setting the random number key, you can control how the random number sequence begins. The command "rng ( 123456789 )" sets the key to 123456789. key 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 key 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 key, you can control how the random number sequence begins. The command "rng ( 123456789 )" sets the key to 123456789. key has been set to 987654321 Now generate 5 random values. RAND() = 0.0729883 RAND() = 0.216037 RAND() = 0.464753 RAND() = 0.62259 RAND() = 0.618388 key has been reset to 987654321 Now generate 5 more random values. RAND() = 0.0729883 RAND() = 0.216037 RAND() = 0.464753 RAND() = 0.62259 RAND() = 0.618388 RAND_TEST02: By setting the random number key, you can control how the random number sequence begins. The command "rng ( 123456789 )" sets the key to 123456789. key 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 key 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. randi_test(): 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 = 1 b = 2 7 8 8 7 c = 9 6 8 8 2 d = 1 1 2 1 1 3 3 1 3 3 1 4 e = 3 1 3 4 1 2 2 3 4 3 4 1 2 4 4 1 4 2 1 4 3 4 1 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 = 10 b = 7 8 8 7 8 7 7 8 7 7 c = 0 0 1 1 0 d = -3 -4 -2 1 -3 -1 0 -4 3 -4 -3 5 e = 145 173 189 112 147 176 174 166 119 144 110 138 132 133 102 119 125 132 176 185 114 155 111 173 180 RANDI_TEST03: By setting the random number key, you can control how the random number sequence begins. The command "rng ( 123456789 )" sets the key to 123456789. key 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 key 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 key, you can control how the random number sequence begins. The command "rng ( 123456789 )" sets the key to 123456789. key 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 key 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 key, you can control how the random number sequence begins. The command "rng ( 123456789 )" sets the key to 123456789. key 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 key 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. RANDN_TEST(): Test the MATLAB RANDN() function. RANDN_TEST01: In MATLAB, normal random numbers are generated by calling RANDN: A = randn ( ) a random scalar value. B = randn ( 5, 1 ) a random column vector of 5 entries. C = randn ( 1, 5 ) a random row vector of 5 entries. D = randn ( 3, 4 ) a 3 by 4 random matrix. E = randn ( 5 ) a 5 by 5 random matrix. a = 0.3268 b = 1.8057 -1.8334 0.5099 0.3312 0.7392 c = 0.5453 1.1080 -1.2238 -1.2709 -0.5269 d = -0.8700 1.8432 -0.8437 0.2016 -0.3009 0.3173 -0.3125 -0.6350 -1.5925 1.5608 1.7209 -0.7440 e = 0.2286 2.1226 0.2805 0.0318 -0.1836 -0.5138 1.2578 0.9516 -0.2333 -1.1716 1.9648 -0.4797 -0.3449 0.0111 0.5602 -0.0446 -0.1472 1.4620 0.1133 0.5372 -0.5065 1.0174 -1.6786 0.9071 -1.1506 RANDN_TEST02: By setting the random number key, you can control how the random number sequence begins. The command "rng ( 123456789 )" sets the key to 123456789. key has been set to 123456789 Now generate 5 random values. RANDN() = 0.2265 RANDN() = 0.0256107 RANDN() = 0.0376636 RANDN() = 0.364848 RANDN() = -1.05838 key has been reset to 123456789 Now generate 5 more random values. RANDN() = 0.2265 RANDN() = 0.0256107 RANDN() = 0.0376636 RANDN() = 0.364848 RANDN() = -1.05838 RANDN_TEST02: By setting the random number key, you can control how the random number sequence begins. The command "rng ( 123456789 )" sets the key to 123456789. key has been set to 123456789 Now generate 5 random values. RANDN() = 0.2265 RANDN() = 0.0256107 RANDN() = 0.0376636 RANDN() = 0.364848 RANDN() = -1.05838 key has been reset to 123456789 Now generate 5 more random values. RANDN() = 0.2265 RANDN() = 0.0256107 RANDN() = 0.0376636 RANDN() = 0.364848 RANDN() = -1.05838 RANDN_TEST02: By setting the random number key, you can control how the random number sequence begins. The command "rng ( 123456789 )" sets the key to 123456789. key has been set to 123456789 Now generate 5 random values. RANDN() = 0.2265 RANDN() = 0.0256107 RANDN() = 0.0376636 RANDN() = 0.364848 RANDN() = -1.05838 key has been reset to 123456789 Now generate 5 more random values. RANDN() = 0.2265 RANDN() = 0.0256107 RANDN() = 0.0376636 RANDN() = 0.364848 RANDN() = -1.05838 RANDN_TEST03: Compute a lot of random values. The average should be 0.0 The variance should be 1. N Ave Var 1 0.326832 0.000000 10 0.018427 1.383352 100 0.067092 1.006473 1000 0.023507 0.957141 10000 0.008770 0.996067 100000 -0.000765 1.005725 1000000 -0.000553 1.000134 10000000 0.000093 0.999422 RANDN_TEST(): Normal end of execution. RNG_TEST(): Test the MATLAB random number functions RNG and RAND. RAND_TEST01: Call RAND with no initialization: 1 0.195363 2 0.535675 3 0.00702926 4 0.55554 5 0.0881607 RAND_TEST01: Call RAND with no initialization: 1 0.944708 2 0.103654 3 0.304375 4 0.432127 5 0.0960355 RAND_TEST01: Call RAND with no initialization: 1 0.879497 2 0.496148 3 0.961118 4 0.849969 5 0.484156 RAND_TEST01: Call RAND with no initialization: 1 0.459923 2 0.863491 3 0.836189 4 0.476658 5 0.878615 RAND_TEST01: Call RAND with no initialization: 1 0.114568 2 0.362 3 0.646296 4 0.811799 5 0.943641 RAND_TEST02: Initialize random number generation with RNG(123456789): 1 0.532833 2 0.534137 3 0.509553 4 0.713564 5 0.256999 RAND_TEST02: Initialize random number generation with RNG(123456789): 1 0.532833 2 0.534137 3 0.509553 4 0.713564 5 0.256999 RAND_TEST02: Initialize random number generation with RNG(123456789): 1 0.532833 2 0.534137 3 0.509553 4 0.713564 5 0.256999 RAND_TEST02: Initialize random number generation with RNG(123456789): 1 0.532833 2 0.534137 3 0.509553 4 0.713564 5 0.256999 RAND_TEST02: Initialize random number generation with RNG(123456789): 1 0.532833 2 0.534137 3 0.509553 4 0.713564 5 0.256999 RAND_TEST02: Initialize random number generation with RNG(123456789): 1 0.532833 2 0.534137 3 0.509553 4 0.713564 5 0.256999 RAND_TEST02: Initialize random number generation with RNG(123456790): 1 0.440991 2 0.675734 3 0.0109443 4 0.0398055 5 0.963474 RAND_TEST02: Initialize random number generation with RNG(123456791): 1 0.831864 2 0.651939 3 0.256665 4 0.192159 5 0.715615 RAND_TEST02: Initialize random number generation with RNG(123456789): 1 0.532833 2 0.534137 3 0.509553 4 0.713564 5 0.256999 RAND_TEST02: Initialize random number generation with RNG(123456790): 1 0.440991 2 0.675734 3 0.0109443 4 0.0398055 5 0.963474 RAND_TEST03: Randomly initialize with RNG('shuffle'): 1 0.701616 2 0.280612 3 0.439127 4 0.696246 5 0.995878 RAND_TEST03: Randomly initialize with RNG('shuffle'): 1 0.974077 2 0.227586 3 0.735986 4 0.839731 5 0.271813 RAND_TEST03: Randomly initialize with RNG('shuffle'): 1 0.923801 2 0.791908 3 0.707827 4 0.758788 5 0.70822 RAND_TEST03: Randomly initialize with RNG('shuffle'): 1 0.475845 2 0.69013 3 0.057456 4 0.0418849 5 0.0711027 RAND_TEST03: Randomly initialize with RNG('shuffle'): 1 0.744764 2 0.440096 3 0.0256298 4 0.933942 5 0.899696 RAND_TEST04: Save and restore the RNG state: 1 0.15166 2 0.610128 3 0.989392 4 0.307847 5 0.042317 Restoring RNG state: 1 0.15166 2 0.610128 3 0.989392 4 0.307847 5 0.042317 RNG_TEST: Normal end of execution. matlab_random_test(): Normal end of execution. 07-Jan-2022 23:01:10