This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Random Number Generation”.

1. What is the output of the following code?

T=rand + i*rand

a) A complex number whose real and imaginary parts are whole numbers

b) A complex number whose real and imaginary parts are fractions

c) A complex number whose real and imaginary parts are in the interval (0,1)

d) A complex number whose real and imaginary parts in the interval [0,1]

View Answer

Explanation: The rand function generates numbers in the interval (0,1). Hence, the complex number whose real and imaginary parts are in the interval (0,1)is correct. A complex number whose real and imaginary parts in the interval [0,1]would’ve been correct if the command randi(0,1) was used.

2. What is the output of the following command?

randi(10 5,3)

a) Error

b) A 5*3 matrix of random numbers

c) A 5*3 matrix of random numbers in the interval [1,10]

d) A 583 matrix of random numbers evenly spaced in the interval [1,10]

View Answer

Explanation: The above command is syntactically incorrect. A 5*3 matrix of random numbers in the interval [1,10] would’ve been the correct option if the code was randi(10,5,3) but one comma is missing between 10 and 5. This will give an error in MATLAB.

3. What is the output of the following code?

rng(‘shuffle’)

a) Control the random number generator

b) Control the filter design process

c) Control the IIR design process

d) Control the FIR design process

View Answer

Explanation: Commands like rand, randi use the random number generator to generate the random numbers. This can be controlled by using the rng command. The above command does not generate a result in the command window but it changes the working of the rand command.

4. The randn command generates random numbers by following a _________

a) Normal distribution

b) Normalized Normal Distribution

c) Uniform Distribution

d) Bernoulli’s Distribution

View Answer

Explanation: The Normalized normal distribution is used to generate random numbers random numbers using the randn command- this is the inbuilt working of the randn command. Hence, Normalized Normal Distribution is correct.

5. The output of the following code

randn[(3,4)]

a) Error

b) A random set of numbers from the normalized normal distribution

c) A random set of numbers from the range 3,4

d) A random set of numbers from the normal distribution ranging from 3 to 4

View Answer

Explanation: The above command is syntactically incorrect. The input to the randn command should be within parentheses.

6. What is the class of the variable r after the following code is run?

r=rand(1,4,’double’)

a) Array

b) Single

c) Double

d) Integer

View Answer

Explanation: After the execution of the following command, r will be a 1*4 vector with a class of double. This is because we have defined the class within single inverted commas as double. R is a row vector so, and hence, it is an integer array. But it’s class is double.

7. The linspace command generates pseudorandom numbers.

a) True

b) False

View Answer

Explanation: The linspace commands generate numbers which are equidistant from each other and contain within a closed range. Hence, they are not pseudorandom numbers and the statement is false.

8. What is the error in the following command?

randn[Inf]

a) Error due to Inf

b) Syntactical error

c) Misspelled command

d) No error

View Answer

Explanation: The first error MATLAB sees is that there is a syntactical error. This will be the error which will pop up in the command window. Hence, the Syntactical error is correct. Error due to Inf would’ve been correct if there was no syntactical error. MATLAB returns the first error it founds.

9. The range of numbers returned by the following code is:

randperm(1,9)

a) [1,9]

b) (1,9)

c) [1,9)

d) (1,9]

View Answer

Explanation: The randperm command would return 9 unique values with the permutation of numbers ranging from 1 to 9. The interval is inclusive of both 1 and 9. Hence only option [1,9] is correct. The rest are wrong.

10. What is the output of the following code?

randi(10,1,9)

a) 9 unique values with replacement in the interval [1,10)

b) 9 values with replacement in the interval (1,10]

c) 9 unique values with replacement in the interval (1,10)

d) 9 values with replacement in the interval [1,10]

View Answer

Explanation: We have mentioned the desired number of values within the interval. Hence MATLAB will return only 9 values. The randi command generates random numbers within the specified interval which are not unique.

11. What is the output of the following code?

rand(2,’signed’)

a) A 2*2 matrix of signed data type

b) A 2 element vector of signed data type

c) A 2 element vector

d) Error

View Answer

Explanation: The rand command cannot take signed as a user-defined data type. The available data types are single and double. Hence, this will generate an error.

12. What is the default return type of the rand command?

a) Single

b) Double

c) Signed

d) Unsigned

View Answer

Explanation: The default return type of the rand command is double. It can be changed to single by giving single as a string input to the rand command.

13. The rand command is provided by the __________

a) Parallel Computing Toolbox

b) Signal Processing Toolbox

c) Symbolic Math Toolbox

d) Does not exist

View Answer

Explanation: The parallel Computing Toolbox contains the rand command in MATLAB. The rest of the options are incorrect.

14. What is the output of the following code?

makedist(‘normal’)

a) Error

b) A normal distribution

c) A list of numbers selected randomly from the normal distribution

d) A normalized normal distribution

View Answer

Explanation: If we don’t specify the mean and standard deviation of the normal distribution, the makedist command will generate a normal distribution which is normalized. This means the mean is 0 and a standard deviation is 1.

15. What is the output of the following code?

c=makedist(‘normal’);random(c)

a) An array of random numbers selected from the normalized normal distribution

b) Error due to makedist

c) A random number from the normalized normal distribution

d) Error due to random

View Answer

Explanation: There is no error in the above code. Firstly, a normalized normal distribution would be generated. Thereafter, the random command would select a value from it and display it in the command window.

**Sanfoundry Global Education & Learning Series – MATLAB.**

To practice all areas of MATLAB, __here is complete set of 1000+ Multiple Choice Questions and Answers__.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!