首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用arc4random()?

用arc4random()?
EN

Stack Overflow用户
提问于 2011-11-18 22:36:58
回答 1查看 564关注 0票数 0

在我的游戏中,我知道我可以使用条件,但我想看看是否有一个数学方程式,可以使我更容易。我想用arc4random()

我需要的是:

如果我的分数是1-20,概率:如果我的分数是21-40,概率:1/25

  1. ,如果我的分数是21-40,概率:1/20
  2. ,如果我的分数是41-60,概率:1/15
  3. ,如果我的分数是60+,概率:1/10。g 210

这个是可能的吗?如果是这样的话,我将如何做到这一点?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-18 22:43:57

这应该能起作用(希望这是清楚的!):

代码语言:javascript
复制
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
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8190028

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档