Im trying to do a random number between 3 and 9.
im guessing rand()%3+9. ive tried many differnernt ways and it doesnt seem to work. any help appreciated
Random call in c?
Not quite. Here's a video on how the rand() function works:
http://xoax.net/comp/cpp/console/Lesson2...
Use (rand() % 6) + 3
This goes from 3 to 8. Do you want 9 included?
Reply:It has been a long time since I programmed in C but I seem to remember that the rand() function returns a number between 0 and 1. If that is the case, you would need to multiple it by 6(now you have a number between 0 and 6), then add 3 to it giving you a number between 3 and 9.
Bert
Reply:what version of C?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment