+ 2
how to generate random number in c or cpp with range?
7 Answers
+ 6
As far as I know, we don't have any method to generate random numbers within range. Workaround for this,
rand() % range;
This will generate the random numbers within specified range. Hope it will be useful for you
+ 4
Is this a correct way
#include <iostream>
using namespace std;
int main()
{
//random number
min + rand() % (max - min)
return 0;
}
+ 4
One last thing for you all; don't forget to:
#include <time.h>
and
srand(time(0))
+ 3
actually, it is not that use
min + rand() % (max - min)
+ 2
thank u so much
+ 2
Yes, I assumed that min is 0. If it's not 0 then this is the proper solution.
+ 1
how can generate random coordinates???