for (x = 1; x < 10; x++)
{
(armoPtr + x) ->def = rand() % b + a;
if ((armoPtr + x) -> def > b)
(armoPtr + x) -> def = b;
srand(time(NULL));
(armoPtr + x) -> hp = rand() % 5 + 1;
srand(time(NULL));
(armoPtr + x) -> valOItem = rand() % (lvlpnts + 1) + max(lvlpnts);
if ((armoPtr + x) -> valOItem > (lvlpnts + 1))
(armoPtr + x) -> valOItem = (lvlpnts + 1);
(armoPtr + x) -> valOItem *= 10;
srand(time(NULL));
}
请原谅我,如果这是一个相当平庸的错误,但是这个循环每次循环都不应该有新的随机数吗?我还在Com Sci第一年的第二个学期。对不起,如果我吮吸。哈哈哈
答案 0 :(得分:0)
在开始绘制随机数之前调用srand一次
srand(time(NULL));
for (x = 1; x < 10; x++)
{
然后在循环中调用top rand():
srand(time(NULL));
for (x = 1; x < 10; x++)
{
(armoPtr + x) ->def = rand() % b + a;
if ((armoPtr + x) -> def > b)
(armoPtr + x) -> def = b;
(armoPtr + x) -> hp = rand() % 5 + 1;
(armoPtr + x) -> valOItem = rand() % (lvlpnts + 1) + max(lvlpnts);
if ((armoPtr + x) -> valOItem > (lvlpnts + 1))
(armoPtr + x) -> valOItem = (lvlpnts + 1);
(armoPtr + x) -> valOItem *= 10;
}
在同一秒内多次输入srand with time(NULL)将使你开始从头开始绘制相同的数字,因为time(NULL)粒度是秒。