Let my preface by saying that i haven't programmed in about 6 years. I just started a couple days ago so I realize that my code is inefficient.
In essence I'm trying to generate 6 independent/random values from a deck of cards. Each time I press enter it will run the simulator over again and generate 6 new cards.
Where I run into my problem is that if I hit enter too quickly, the same 6 cards are produced. It seems like I need to wait a half second or so before it will generate new values. Can someone educate me on what's going on here?
/* try this*/
srand(time(NULL));
int mag= 1+ rand() % 6;
/* this prints from 1 to 6
this 1+ added to it is to avoid printing Zero */
for (int n=1;n<=10;n++)
{
cout<<mag;
}
ldm is right, if you have srand(time(0)) in your loop, then your random number generator could be seeded with the same number if less than a second has passed. You should always call srand() once and only once in a program. It's easiest to do it at the start of main().