Why am I getting a different random number each time I run my code in main, but when I run it in a function I am getting a static number?
(1) Random number in Main...
int main()
{
srand(time(0));
int loot = 1+(rand()%9);
cout << loot;
return 0;
}
(2) Random Number in a function outside of main...
using namespace std;
void lootTable(){
srand(time(0));
int loot = 1+(rand()%9);
cout << loot;
}
int main()
{
cout << lootTable;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire