[Question] Random number below a set number

Posts 1–5 of 5 · Page 1 of 1
[Question] Random number below a set number
OK, so basically I want to make a guessing game. The variable "CorrectGuess" should be random. I found a lot of articles on random numbers, ranging from printing out 1-10 to just generating any old number. I want the number to be less then AND greater then a certain number. (Like greater then 1 less then 100) Any help on this subject would be extremely appreciated.
Quote Originally Posted by That0n3Guy View Post
OK, so basically I want to make a guessing game. The variable "CorrectGuess" should be random. I found a lot of articles on random numbers, ranging from printing out 1-10 to just generating any old number. I want the number to be less then AND greater then a certain number. (Like greater then 1 less then 100) Any help on this subject would be extremely appreciated.
I've actually always wanted to do this, because the rand() in Java is different from the rand() in C++. Basically all you need to do is call rand() and then "mod" it '%' by watever values you want the random number between.

So:
Code:
rand() % 10;
Would give you values between 0-9;
Code:
 rand()% 10 +1;
Would give you values between 1-10;

rand - C++ Reference
Thank you both for your replies, I'm going to look into it.
Posts 1–5 of 5 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

Talk with us