Home » Ask & Discuss » Board Exams - CBSE, ICSE, State Boards » Computer Science « Back to Discussion
Computer Science
Comments (3)
23 Sep 2009 21:36:54 IST
Like
0 people liked this
hello dear
The C++ standard library includes a pseudo random number generator for generating random numbers. In order to use it we need to include the <cstdlib> header. To generate a random number we use the rand() function.
here i will generate a single random number:
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int random_integer = rand();
cout << random_integer << endl;
}













int a=rand()
to get numbers in a range say 0 to 9
int a=rand() % 10
you need cstdlib for this