programming-examples/c++/Numerical_Problems/C++ Program to Use rand and srand Functions.cpp

20 lines
405 B
C++
Raw Normal View History

2019-11-18 14:44:36 +01:00
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main(int argc, char **argv)
{
cout << "First number: " << rand() % 100;
srand(time(NULL));
cout << "\nRandom number: " << rand() % 100;
srand(1);
cout << "\nAgain the first number: " << rand() % 100;
return 0;
}
/*
First number: 41
Random number: 98
Again the first number: 41