#include %26lt;iostream%26gt;
#include %26lt;cstdlib%26gt;
#include %26lt;time.h%26gt;
int main()
{
/*
Declare variable to hold seconds on clock.
*/
time_t seconds;
/*
Get value from system clock and
place in seconds variable.
*/
time(%26amp;seconds);
/*
Convert seconds to a unsigned
integer.
*/
srand((unsigned int) seconds);
/*
Output random values.
*/
cout%26lt;%26lt; rand() %26lt;%26lt; endl;
cout%26lt;%26lt; rand() %26lt;%26lt; endl;
cout%26lt;%26lt; rand() %26lt;%26lt; endl;
return 0;
}
What wiil be code for generating a random number in c++?
there is a 'rand' function to generate it. See help.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment