Problem with rand()

I used the function rand(), of the library <cstdlib>, to generate a random number and everytime I run it it returns 41.

1
2
3
4
5
6
7
8
9
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
cout<<rand();

return 0;
}


What's the problem?

Post scriptum: I have now run it on an online compiler and it always returns 1804289383.
Last edited on
Seed the random number generator, once at the beginning of the program.
There is an example on this page: http://en.cppreference.com/w/cpp/numeric/random/srand
Thank you JLBorges, it worked.
Topic archived. No new replies allowed.