lundi 4 février 2019

RNG problem making a cards game, and the time(0) function [duplicate]

This question already has an answer here:

I am making a cards game called "ACEYDU" in C++. The rules of the game are as follows: The dealer deals two cards and the player decides to bet if the next dealt card is within the interval of the two other cards. If not then two more cards are dealt and repeat the process. If the player decides to bet, one more card is dealt, the player either wins or loses money, then two more cards are dealt and repeat the process.

My code is here: https://gist.github.com/Lastrevio112/7e2e87424829ba2ed03d5e2fe29f7a1a#file-gistfile1-txt

The problem is around lines 20-35, so focus on those and just skim through the rest if the code seems too long. What happens is if i press n in less than a second I have to do it twice, or even 3 or 4 times. So I will press n and the two numbers on screen won't change. I'm guessing this is because of something related to the time(0) function as how much you have to wait for new numbers seems to be one second.

At the srand(time(0)+rand()+rand()); and srand(time(0)+rand()+rand()+rand()); lines I added many +rand() to make sure I don't get the same numbers or something, to maximize the randomness, in case those lines same weird.

I tried removing the srand( time(0) ); line inside the while loop (about making sure the two cards dealt aren't the same), but I had the same problem.

Also is there a problem with my random number generator in general without that part? I noticed before I put it that I got identical cards quite too often, or one card similar to the one of the two last dealt cards.




Aucun commentaire:

Enregistrer un commentaire