【发布时间】:2013-06-04 23:02:54
【问题描述】:
到目前为止,我有一个简单的程序可以创建 5 张公共卡片(全部为整数)。我已经设法设置了这些(它们是全局变量,这是故意的),但是每次我运行程序时,它们都会创建相同的数字。下面是代码。
int communityCards[5];
int playerCards[2];
int opponentCards[2];
int communityValues[5];
int playerValues[2];
int opponentValues[2];
int main(int argc, const char * argv[]) {
for (int i = 0; i < 9; i++) {
if (i < 5) {
communityCards[i] = rand() % 52 - i;
for (int a = 0; communityCards[a]!=0; a++) {
communityCards[i]==communityCards[a]?communityCards[i]++: a = a;
}
}
printf("%i ", communityCards[i]);
}
}
【问题讨论】:
-
查看手册即可。你必须先打电话给
srand。 -
您应该开始使用更新的随机生成器。 cplusplus.com/reference/random/uniform_real_distribution/…
-
@user814628 - 这不会改变不播种生成器的行为。该程序在每次运行时仍会产生相同的一组值。