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.

advertisement

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.
advertisement

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.

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!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.