如何以给定的百分比创建概率? [英] How to create a probability by a given percentage?

查看:195
本文介绍了如何以给定的百分比创建概率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为游戏创建基于百分比的概率.例如.如果某件商品有45%的几率是致命命中,那必须表示它有100命中中有45命中率是至关重要的.

首先,我尝试使用一种简单的解决方案:

R = new Random();
int C = R.Next(1, 101);
if (C <= ProbabilityPercent) DoSomething()

但是在100次迭代中,例如48%,满分为40-52(满分100). 同样适用于49、50、51. 因此,这些百分比"之间没有区别.

问题是如何设置百分比,例如50,并且严格随机获得100中的50? 对于有机会发现稀有物品的可能性增加增加找到物品的机会,这是非常重要的事情.因此1%的增益会很有意义,因为现在不是.

对不起,我的英语不好.

解决方案

您只需要考虑重复卷的均匀分布.

您不能查看超过100卷,因为强迫它精确地产生 45 不会是随机的.通常,这样的纸卷应该表现出记忆力不足".例如,如果掷骰子寻找6,则您有1比6的机会.如果您将其掷出5次,而没有获得6倍,则:在下一卷中获得6的机会不是1.仍然是1比6.因此,您只能看看它的满足程度您对统计上的大量事件进行摊销时的期望... 100,000说.

基本上:您当前的代码很好.如果用户知道(因为他们已经击中55次而没有暴击),则接下来的45次击必须是暴击,那么它不再是随机的,他们可以玩系统了.

也; 45%暴击的几率似乎有点高; p

I'm trying to create a percentage-based probability for a game. E.g. if an item has a 45% chance of a critical hit, that must mean it is 45 of 100 hits would be critical.

First, I tried to use a simple solution:

R = new Random();
int C = R.Next(1, 101);
if (C <= ProbabilityPercent) DoSomething()

But in 100 iterations with a chance of e.g. 48%, it gives 40-52 out of 100. Same goes for 49, 50, 51. So, there is no difference between these "percents".

The question is how to set a percentage of e.g. 50, and get strictly 50 of 100 with random? It is a very important thing for probability of rare item finding with an opportunity to increase a chance to find with an item. So the buff of 1% would be sensinble, because now it is not.

Sorry for my bad English.

解决方案

You need to think only in terms of uniform distribution over repeated rolls.

You can't look over 100 rolls, because forcing that to yield exactly 45 would not be random. Usually, such rolls should exhibit "lack of memory". For example, if you roll a dice looking for a 6, you have a 1-in-6 chance. If you roll it 5 times, and don't get a six - then: the chance of getting a 6 on the next roll is not 1. It is still 1 in 6. As such, you can only look at how well it met your expectation when amortized over a statistically large number of events... 100,000 say.

Basically: your current code is fine. If the user knows (because they've hit 55 times without a critical) that the next 45 hits must be critical, then it is no longer random and they can game the system.

Also; 45% chance of critical hit seems a bit high ;p

这篇关于如何以给定的百分比创建概率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆