In the code below I use the same time based random number generator for both the commented out section and the non-commented section. However every time I compile the commented code generates numbers that gradually increase instead of being random. In the non-commented code the 100 generated numbers seem much more random when I find their remainder of 100. How do I make the commented out code generate seemingly more random numbers.
#include <stdafx.h>
#include <iostream>
#include <cstdlib> // for rand() and srand()
#include <ctime> // for time()
using namespace std;
int main()
{
srand(time(0)); // set initial seed value to system clock
/*int x = rand() % 100 + 1;
cout << x << endl; */
for (int nCount=0; nCount < 100; ++nCount)
{
cout << rand() << ":";
cout << rand() % 100 << " ";
if ((nCount+1) % 5 == 0)
cout << endl;
}
}
Aucun commentaire:
Enregistrer un commentaire