This course teaches how to install and configure Windows Server 2012 R2. It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Hey Experts! Fully admit that I am working on something that is slightly outside my realm but I'm very interested in learning how to make this work so your help is greatly appreciated.

For software being developed, I'm trying to build a formula to calculate the success of an event (build a wooden crate) based on factors like character's smarts (+10% increase in success), speed (+5% increase in success) and ability (+15% increase in success).

I've been looking all over the internet for how to build this equation or how to determine success/failure. I've written formulas for Excel but not something like this so I appreciate your help and time.

For software being developed, I'm trying to build a formula to calculate the success of an event (build a wooden crate) based on factors like character's smarts (+10% increase in success), speed (+5% increase in success) and ability (+15% increase in success).

I've been looking all over the internet for how to build this equation or how to determine success/failure. I've written formulas for Excel but not something like this so I appreciate your help and time.

Do more with

EXPERT OFFICE^{®} is a registered trademark of EXPERTS EXCHANGE^{®}

The larger question you need to answer is what do YOU want the formula to look like?

Is it purely chance?

Is it calculated each time tried?

Do # of tries make a difference in chance of success?

What are the total chances of success?

how do the modifiers stack?

To give an example:

For generating a random number, total chances could be calculated as out of 100% or any arbirary number.

in simplest terms you might as a person has a 1 in 100 chance of success.

So using this pseudo PS Code:

```
IF ( Rand(99) -eq 0) { "SUCCESS!"}
```

So you have a function "RAND" which you give a rnad max to, and it returns a random number between 0 and 99 (100 chances), if we rolled a 0 we are successful (I chose this because in most languages the Random number generator includes 0, and in most languages 0 is "FALSE" and in many languages you can check for "NOT FALSE" which is the quickest executing way of checking the result as:)

```
IF ( ! Rand(99) ) { "SUCCESS!"}
```

This can be defined as a 1%, 1/100, or 1 in 100 chance

But how do you r modifiers modify that?

are they multiplicative?

Additive?

is it possible to have or exceed 100%?

Lets say you have the normal equation

- $X = 1 = 100% Chance X= 0 = 0% Chance
- $X = 0.1 = 10% Chance - 1/10, or 1 in 10
- $X = 0.01 = 1% Chance - 1/100, or 1 in 100

Now what is the BASE % Chance. It is not going to be 0, or if it is you have to write SPECIAL code to check and handle that, which you we'll avoid as it's unlikely to be nessessary.

Lets say for argument purposes you have a 10 percent chance 1/10 or 0.1

$X= 0.1

We can modify our Existing test for Success mightily easily if we want to use this!

```
IF ( Rand( ( (1/$X)-1) ) -eq 0) { "SUCCESS!"}
```

Wait Q, what's all this then?

Its a method to set the chances to whatever you like.

but 0 to 10 is 11 chances

so we must subtract 1 so the function checks from 0 to 9 for 10 chances

.

-1 is 99

0 to 99 is 100 chances

0 to 4 is 5 chances, so again -1 = 3 and the function will return {0,1,2,3} and if we find 0 we have a success!

Probability of success = Minimum(100% or Smarts * Speed * Ability*Base probability of success)

You will need to establish ranges for each of the parameters, such as 25% to 200%.

The Base probability of success is what you want the likelihood of outcome to be when every character attribute is 100%. Let's say it is 52%. Your character will succeed 100% of time if Smarts = 125%, Speed = 110% and Ability = 140%.

The reason for the Minimum function is in case (Smarts * Speed * Ability*Base probability of success) exceeds 100%. If you want there to be a small chance that the character will fail even if all attributes are maxed out, then change the 100% in the minimum to say 90% .

If (random number between 0 and 1) >= probability of success then the task was completed successfully, otherwise, it failed.

If your calculated probability of success using character attributes is 90%, then you compare that value to a uniformly distributed random number chosen between 0 and 1. If the random number is 0.1 or higher, then success occurred. Otherwise, failure.

If (random number between 0 and 1) >= (100% - probability of success) then attempt succeeded, otherwise failed

Now, for your modifiers, how will they apply?

Do they add a flat % chance?

or do they modify the total percent chance by some value?

do they come all in a row? do they stack? do you use the highest one?

Those are choice you have to decide. but I can show some examples here too.

IE if you want to make them additive and already have them defined as %s of 100:

factors like character's smarts (+10% increase in success), speed (+5% increase in success) and ability (+15% increase in success).

Lets assume they are additive for now thats the "simple" scenario

You're probably tracking these traits as whole numbers:

```
$Smarts_Lvl=10
$Speed_Lvl=5
$Ability_Lvl=15
```

Lets assume for now that you just want them all to apply equally to the chances of success as you've already told me the % chances of each one:

```
$Smarts_Chance=(100/$Smarts_Lvl)
$Speed_Chance=(100/$Speed_Lvl)
$Ability_Chance=(100/$Ability_Lvl)
```

Before we go any further lets address this, in our original example we only cared about the chance X which we said was the Base Chance

```
IF ( Rand( ( (1/$X)-1) ) -eq 0) { "SUCCESS!"}
```

But really X is the "Total Chance" so lets rewrite this to have:

$Total_Chance

```
IF ( Rand( ( ( 1 / $Total_Chance ) - 1) ) -eq 0) { "SUCCESS!"}
```

And we'll call the Base Chance $Base_chance instead of X.

$Base_chance = 0.1

```
$Total_Chance = ( $Base_chance, $Smarts_Chance, $Speed_Chance, $Ability_Chance | Measure-Object -sum ).sum
```

And then check our success

```
IF ( Rand( ( ( 1 / $Total_Chance ) - 1) ) -eq 0) { "SUCCESS!"}
```

in Powershell the Get_random function doesn't need the -1 done (it does it for you! Unlike CMD!) so I was about to write this up ad a batch example but now I'm sticking with a quick powershell.

In oversimplifying my initial equations I forgot that it's impractical to have non integer numbers.

So I would ammed slightly as well.

```
$Percent_Success_Base=10
$Percent_Success_Max=90
[PSCustomObject]$Character=@{
Smarts=10
Speed=5
Ability=15}
#Sum the Percent Chances and set a max value.
$Percent_Success_Total = [math]::Min((($Character.Values | Measure-Object -sum).sum + $Percent_Success_Base ),$Percent_Success_Max)
for ($J=1; $J -lt 13; $J++) {
$Rand=Get-Random -Maximum ( 100 ) # So we we can output the results
IF ( $Rand -lt $Percent_Success_Total) {
Write-Host "SUCCESS! - $Rand is Less than $Percent_Success_Total" -ForeGroundColor Green
} ELSE {
Write-Host "FAILURE! - $Rand is More than $Percent_Success_Total" -ForeGroundColor Red
}
}
```

## Premium Content

You need an Expert Office subscription to comment.Start Free Trial