Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a probability by a given percentage?

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.

like image 419
maelstrom Avatar asked Nov 12 '12 10:11

maelstrom


People also ask

How do you find the probability with percentages?

You calculate probability by dividing the number of successes by the total number of attempts. Your result will be a number between 0 and 1, which can also be expressed as a percent if you multiply the number by 100%.

What is the probability of 100%?

If an event has only one possible outcome, the probability for this outcome is always 1 (or 100 percent).

What does a probability of 10% mean?

A probability of 0.1 means there is a 1 in 10 chance of an event happening, or a 10% chance that an event will happen. Weather forecasters might tell us that there is a 70% chance of rain.

What is the probability of a 1% chance?

So that means that, for example, if you roll a 100-sided die, then the probability of any individual value is 1%, i.e. P(1)=P(2)=P(3)=… =P(100)=0.01.


1 Answers

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

like image 106
Marc Gravell Avatar answered Sep 27 '22 18:09

Marc Gravell