Generates 10 pseudorandom numbers with C++'s rand() function - C++ Data Type

C++ examples for Data Type:Random

Description

Generates 10 pseudorandom numbers with C++'s rand() function

Demo Code

#include <iostream>
#include <cmath>
#include <ctime>
using namespace std;
int main()//  w w w .  jav a  2 s.  c  om
{
   const int NUMBERS = 10;
   double randvalue;
   int i;
   srand(time(NULL));  // generates the first seed value
   for (i = 1; i <= NUMBERS; i++)
   {
      randvalue = rand();
      cout << randvalue << endl;
   }
   return 0;
}

Result


Related Tutorials