In the program below what is the difference between rand and srand? My book says that rand returns an int between 0 and RAND_MAX, which is never smaller than 32,767. Yet this code returns a number from 1-6, how is that? I see the line ( rand() % 6 ) + 1
but I don't see how that would give a number from 1-6.
lewashby
56
Junior Poster
Recommended Answers
Jump to PostIn the program below what is the difference between rand and srand?
rand
generates a pseudorandom number.srand
seeds the generator thatrand
uses. The seed essentially determines what the first random number will be and affects subsequent numbers in the sequence. If you don't callsrand
, the …
Jump to PostWe would be remiss if we did not point out that
rand
is deprecated and really should not be used. Some of the implementations of it are fist-bitingly bad.http://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful
Welcome to C++11's …
All 5 Replies
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
Moschops
683
Practically a Master Poster
Featured Poster
L7Sqr
227
Practically a Master Poster
Rashakil Fol
978
Super Senior Demiposter
Team Colleague
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.