Answer the question
In order to leave comments, you need to log in
How to correctly set the range of random numbers with the rand function?
There is an array of 1000 elements. I need to set the interval a,b where a and b are random numbers. But at the same time, the interval should not "drop in" beyond the border of my array of 1000 elements.
for (int i =1; i<=1000; ++i) //кол-во запросов
{
int a = rand() % 1000;
int b = rand() % 1000;
if (a > b) {
int tmp_b = b;
b = a;
a = tmp_b;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question