+ 1
How can i get random no. each time i run the program
I want to get random no. (not same as ever before) each time I run the program. each and every time different when I terminate and again run the program
4 odpowiedzi
+ 6
Use rand() to generate random number
+ 6
add srand(time(NULL)); at the begining of your code
https://www.sololearn.com/discuss/218265/?ref=app
+ 2
use rand() in c++ to get random number
ex -
#include<iostream>
using namespace std;
int main()
{
for(x=0; x<10; x++)
{
cout<<rand()<<endl;
}
return 0;
}
it will give you the random number. If You will use % then you will get random number in a specific range
+ 1
I m not asking that
I mean suppose within range (1-10) it will give
1
4
6
5
and next time
2
9
8
7
and next time
3
10, only
no more outputs
never ever repeat no.
even I shut the system and run again