只需编写一个程序来洗牌一副扑克牌,并获得取决于RNG是否内部或外部的for循环播种不同的行为; 即。
for(int i = 0; i < 52; i++)
{
srand(time(0));
Card temp = deck[i];
int toSwap = rand()%52;
deck[i] = deck[toSwap];
deck[toSwap] = temp;
}
使输出
Nine of Hearts
Ace of Clubs
Two of Clubs
Three of Clubs
Four of Clubs
等,但
void DeckOfCards::shuffle()
{
srand(time(0));
for(int i = 0; i < 52; i++)
{
Card temp = deck[i];
int toSwap = rand()%52;
deck[i] = deck[toSwap];
deck[toSwap] = temp;
}
currentCard =0;
}
导致
Ace of Hearts
Queen of Spades
Four of Hearts
Seven of Clubs
Five of Hearts
(正确的功能)。 任何人都知道为什么再接种RNG会导致此?