fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std; // consider removing this line in serious projects
  5.  
  6. int GetRandomInt(){
  7.  
  8. unsigned int seed = time(0);
  9.  
  10. srand(seed);
  11. int randomInt = rand() % 6;
  12.  
  13. return randomInt;
  14. }
  15.  
  16. int main() {
  17. cout << "Random Integer: " << GetRandomInt();
  18. }
  19.  
  20.  
Success #stdin #stdout 0.01s 5256KB
stdin
stdout
Random Integer: 2