Generating random numbers

Jun 1, 2019 at 4:12pm
How to generate random number between 7 and 8?
9 and 10?
11 and 12?


Jun 1, 2019 at 4:25pm
Last edited on Jun 1, 2019 at 4:27pm
Jun 1, 2019 at 4:31pm
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 ;)
Jun 1, 2019 at 5:16pm
you guys are making this complicated.
1
2
3
srand(time(0))
int x = rand () % 2 + 7


like that
Jun 1, 2019 at 5:39pm
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);
Jun 1, 2019 at 6:04pm
like that

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