//unable to display angle brackets due to html
#include 《iostream》
#include 《ctime》
using namespace std;
//with no srand, the default value will be 1 and
//random numbers will keep repeating. With constant
//seed value of srand eg.4, the random numbers will
//also repeat. Therefore using time as seed for srand
//will ensure random numbers will be different.
//time is the number of seconds since Jan 1, 1970
int main()
{
//srand(4);
srand( (int) time ( 0 ));
for (int i = 0; i < 5; i++)
{
printf("%d\n" , (rand( ) %101) );
}
}
Like this:
Like Loading...
Related