我想使用 2 个变量中的随机数进行乘法测验。 我尝试使用这个:
int answ
int rand1= (arc4random()%10)+1;
int rand2= (arc4random()%20)+1;
printf("\n¿What is %d * %d?: ", rand1, rand2);
scanf("%d", &answ);
if (answ==rand1*rand2)
printf("\nCorrect answer!");
else
printf("\Incorrect answer, the result was %d", rand1*rand2);
我的问题是,当提出下一个问题时,两个随机数都没有改变。 我还尝试添加 srand(time(NULL)) 和相同的..(我已经添加了库 stdlib.h)
缺少什么?
最佳答案
arc4random()
不需要播种,并且将返回与任何先前返回的数字无关的随机数。
您的程序存在问题,导致您没有对 arc4random()
进行新的调用,或者没有使用新值。您如何要求重新运行?
srand(time(NULL))
与 arc4random()
无关。
请注意,您可以使用 arc4random_uniform(10)
代替 arc4random()%10)
。
关于c - Xcode 上的 arc4random C 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27728143/