Can you make a rand in C less predictable?

37 Views Asked by At

I'm new to C and making a simple blackjack console app. When drawing a new card, I use the srand function to determine what card is pulled. The cards are random, but it's very predictable... For example, if a 2 is pulled, I know the other card will be a King. It follows that pattern on every single card. So I was curious, is there a way to make it less predictable? Or is this just C being C?

Here's my code:

int lower = 1;                                    // Lowest number for the RNG
int upper = 13;                                   // Highest number for the RNG
srand(time(NULL));                                // srand to actually randomize the numbers generated
int rng = (rand() % (upper - lower + 1)) + lower; // Randomly generated number
0

There are 0 best solutions below