C Programming Questions and Answers – Random Number Generation – 1

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

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

1. What is function srand(unsigned)?
a) Sets the seed for rand
b) Doesn’t exist
c) Is an error
d) None of the mentioned
View Answer

Answer: a
Explanation: None.

2. Which is the best way to generate numbers between 0 to 99?
a) rand()-100
b) rand()%100
c) rand(100)
d) srand(100)
View Answer

Answer: b
Explanation: None.
advertisement
advertisement

3. Which is the correct way to generate numbers between minimum and maximum(inclusive)?
a) minimum + (rand() % (maximum – minimum));
b) minimum + (rand() % (maximum – minimum + 1));
c) minimum * (rand() % (maximum – minimum))
d) minimum – (rand() % (maximum + minimum));
View Answer

Answer: b
Explanation: None.

4. rand() and srand() functions are used _____________
a) To find sqrt
b) For and operations
c) For or operations
d) To generate random numbers
View Answer

Answer: d
Explanation: None.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

5. What is the return type of rand() function?
a) short
b) int
c) long
d) double
View Answer

Answer: b
Explanation: None.

6. Which of the following can be used for random number generation?
a) random()
b) rnd()
c) rndm()
d) none of the mentioned
View Answer

Answer: a
Explanation: None.
advertisement

7. Which of the following snippet will effectively generate random numbers?
a) rand();
b) rand(10);
c) rand(time(NULL));
d) all of the mentioned
View Answer

Answer: a
Explanation: None.

8. Which among the following is correct function call for rand() and random()?
a) rand() and random();
b) rand() and random(1);
c) rand(1) and random(1);
d) rand(1) and random();
View Answer

Answer: a
Explanation: None.
advertisement

9. For the function call time(), what type of parameter is accepted?
a) int
b) int *
c) time_t
d) time_t *
View Answer

Answer: d
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). 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!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.