Tuesday, July 22, 2008, 12:08 PM
Posted by Administrator
SO: Microsoft Windows\PosixPosted by Administrator
Type: Random Number
Language: C++
Title: Random Number in C++
To generate random number in C\C++ we can use the functions rand() and srand().
The first function generate a pseudo\random number and srand set the start of random generation, this information are a integer.
WARNING: if you use only rand function the result of the function are predictable. A good example are this.
#include <stdio.h>
#include <strlib.h>
#include <time.h>
int main()
{
srand(time(0));
int rand1 = rand() % 10; //random number da 0 - 9
return 0;
}




( 3 / 536 )

Calendar



