0

I'm keeping on trying on various online editor,but the result is the same

#include <iostream>
#include <cstdlib>  
int main() {
    std::cout << rand(); 
}
drescherjm
  • 10,365
  • 5
  • 44
  • 64
Fabbiucciello
  • 1,514
  • 2
  • 4
  • 9
  • 6
    Because you haven't called `srand()`, which is a requirement for obtaining random numbers from `rand()` –  Jun 16 '21 at 23:19
  • 5
    _"...srand() seeds the pseudo-random number generator used by rand(). If rand() is used before any calls to srand(), rand() behaves __as if it was seeded with srand(1)__..."_ https://en.cppreference.com/w/c/numeric/random/rand – Richard Critten Jun 16 '21 at 23:20
  • 3
    Side note: [rand() Considered Harmful](https://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful) A good and humorous look at how easy it is to get things wrong with `rand`, how hard it is to get them right, and the modern C++ solution that you should be using instead. – user4581301 Jun 16 '21 at 23:47

0 Answers0