Generating random numbers

How to generate random number between 7 and 8?
9 and 10?
11 and 12?


Last edited on
How to generate random number between 7 and 8?
There are no more (integer) numbers between 7 and 8, neither between 9 and 10 nor 11 and 12. 8 follows directly after 7 in sequence, etc.

In case you'd like funny numbers with that annoying decimal point, get random between 70 and 80 and divide by 10. If that is not enough, generate between 700 and 800 and divide by 100. For 9..10 and 11..12 try yourself or start a new thread ;)
you guys are making this complicated.
1
2
3
srand(time(0))
int x = rand () % 2 + 7


like that
Why do you ask, if you think that you know the answer?

Why do you call expressive, self-documenting, modern C++ solution complicated?
std::uniform_int_distribution<int> distribution(7, 8);
like that

Like that is not between. [7, 8] and ]7, 8[ makes a difference.
Topic archived. No new replies allowed.