250+ TOP MCQs on Random Number Generation and Answers

C Objective Questions on “Random Number Generation”. One shall practice these Objective Questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C Objective Questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C Objective Questions on “Random Number Generation” along with answers, explanations and/or solutions:

1. What will be the output of the following C code?

  1.     #include 
  2.     #include 
  3.     int main()
  4.     {
  5.         printf("%dn", rand() % 1000);
  6.         return 0;
  7.     }

a) Compile time error
b) An integer between 0-1000
c) An integer between 0-999 including 0 and 999
d) An integer between 0-1000 including 1000
Answer: c
Clarification: None.

2. What will be the output of the following C code?

  1.     #include 
  2.     #include 
  3.     int main()
  4.     {
  5.         srand(9000);
  6.         printf("%dn", rand());
  7.         return 0;
  8.     }

a) Compile time error
b) An integer in the range 0 to RAND_MAX
c) A double in the range 0 to 1
d) A float in the range 0 to 1
Answer: b
Clarification: None.

3. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         printf("%dn", srand(9000));
  5.         return 0;
  6.     }

a) Compile time error
b) An integer in the range 0 to 9000
c) A float in the range 0 to 1
d) A double in the range 0 to 9000
Answer: a
Clarification: None.

4. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         srand(time(NULL));
  5.         printf("%dn", rand());
  6.         return 0;
  7.     }

a) Compile time error
b) An integer in the range 0 to RAND_MAX
c) A double in the range 0 to 1
d) A float in the range 0 to 1
Answer: b
Clarification: None.

5. In the below C program, every time program is run different numbers are generated.

  1.     #include 
  2.     #include 
  3.     int main()
  4.     {
  5.         printf("%dn", rand());
  6.         return 0;
  7.     }

a) True
b) False
c) Depends on the platform
d) Depends on the compiler
Answer: b
Clarification: None.

6. In the following C program, every time program is run different numbers are generated.

  1.     #include 
  2.     int main()
  3.     {
  4.         srand(time(NULL));
  5.         printf("%dn", rand());
  6.         return 0;
  7.     }

a) True
b) False
c) Depends on the platform
d) Depends on the compiler
Answer: a
Clarification: None.

7. Which of these is a correct way to generate numbers between 0 to 1(inclusive) randomly?
a) rand() / RAND_MAX
b) rand() % 2
c) rand(0, 1)
d) none of the mentioned
Answer: a
Clarification: None.

Leave a Reply

Your email address will not be published. Required fields are marked *