+ 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

9th Apr 2017, 5:08 AM
Ankit
4 Answers
+ 6
Use rand() to generate random number
9th Apr 2017, 5:09 AM
Sachin Artani
Sachin Artani - avatar
+ 6
add srand(time(NULL)); at the begining of your code https://www.sololearn.com/discuss/218265/?ref=app
9th Apr 2017, 5:27 AM
Burey
Burey - avatar
+ 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
9th Apr 2017, 5:18 AM
m8riix
m8riix - avatar
+ 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
9th Apr 2017, 4:32 PM
Ankit