Using the Random Number Generator - C++ Data Type

C++ examples for Data Type:Random

Description

Using the Random Number Generator

Demo Code

#include <iostream> 
#include <time.h> 
#include <stdlib.h> 

using namespace std; 

int main(){ //from  w w w.  j  av a 2 s  .c  o  m
    // Always set a seed value. 
    srand((unsigned int)time(NULL)); 

    int RandomValue = rand() % 12; 
    cout << "The random month number is: " << RandomValue + 1 << endl; 

    return 0; 
}

Result


Related Tutorials