|
|
|||||
|
Get the Ebook
C Tutorial
Source Code
Function Reference
|
rand()Prototype: int rand();Header File: stdlib.h (C) or cstdlib (C++) Explanation: rand returns a value between(inclusive) 0 and and RAND_MAX (defined by the compiler, often 32767). To get a more mangeale number, simply use the % operator, which returns the remainder of division. Example:
//Program returns a random number
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
cout<<rand();
cout<<rand()%6; //Number between 0 and 5
}
Other Functions
Want to become a C++ programmer? The Cprogramming.com ebook, Jumping into C++, will walk you through it, step-by-step. Get Jumping into C++ today!
Popular pages
Custom Search
|
||||