Is there a good webpage that explains how to use rand() and srand() correctly? Overall I need to learn how to generate a number between 0 and 3.
riahc3 50 Â Team Colleague
Recommended Answers
Jump to Post— Narue 5,707>This is C++.
That really changes nothing, rand and srand usage remains the same across the two languages. another one that I'd recommend for obvious reasons.
Jump to Post— Narue 5,707>I do not understand the code. Thats why I wanted a page in C that
>tells me how to use rand()/srand() to generate a number between 0 and 3.
Sorry, I'm not smart enough to dumb it down enough for you to understand. If you can't takeint r = …
Jump to Post— Nick Evan 4,005take
int r = rand() % N;and turn it intoint r = rand() % 4;So what: N is now 4? But because you say so? And why 4/n?
You asked for 0-3 right? How many numbers are that? Holy ****! It's four!
If there is a …
All 13 Replies
devnar 114 Junior Poster
riahc3 50 Â Team Colleague
Narue 5,707 Bad Cop Team Colleague
riahc3 50 Â Team Colleague
Narue 5,707 Bad Cop Team Colleague
riahc3 50 Â Team Colleague
Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster
minas1 1 Junior Poster in Training
riahc3 50 Â Team Colleague
riahc3 50 Â Team Colleague
Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster
Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster
Narue 5,707 Bad Cop Team Colleague
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.