The value of the random number cannot be larger than the number of cards. The modulus operator takes the number generated by random() and divides by 52 producing the remainder as a result. This number will range from 0-51, the 52 indices of the deck array. The value of random(), before applying modulus will, under most circumstances, far exceed the size of the array.
add the following
bold code to the "do" loop in the Cards project and you can inspect the value of the generated random number.
Code:
do {
// Generate 2 random numbers to determine which cards to swap
randomA = random() % 52;
randomB = random() % 52;
printf("Random is %ld",random());
This should clarify why modulus is needed; to limit the range of numbers.
Bob