在我的游戏中,我知道我可以使用条件,但我想看看是否有一个数学方程式,可以使我更容易。我想用arc4random()。
我需要的是:
如果我的分数是1-20,概率:如果我的分数是21-40,概率:1/25
g 210这个是可能的吗?如果是这样的话,我将如何做到这一点?
谢谢!
发布于 2011-11-18 22:43:57
这应该能起作用(希望这是清楚的!):
int modNumber = 25;
float alteredScore = score - (floor((score-1)/60) - 1) * 60;
modNumber -= floor((alteredScore-1)/20) * 5;
int result = arc4random() % modNumber; // Or arc4random_uniform(modNumber) if you want to completely remove modulo bias, but beaing in mind the non-randomness (!) of arc4random and the size of modNumber I highly doubt it would make any real difference
if (!result) {
// Result is 0
// Do stuff for the lucky person
} else {
// Make them miserable
}https://stackoverflow.com/questions/8190028
复制相似问题