Skip to content

Instantly share code, notes, and snippets.

@Pome-ro
Created December 10, 2018 21:29
Show Gist options
  • Save Pome-ro/2efe1938e99fa3b6a26ab9621a5846d8 to your computer and use it in GitHub Desktop.
Save Pome-ro/2efe1938e99fa3b6a26ab9621a5846d8 to your computer and use it in GitHub Desktop.
Test the Difficulty Class of a given trap/event/skill in D&D
function Test-DC {
param (
# Parameter help description
[Parameter()]
[int]
$DC,
[Parameter()]
[int]
$Bonus,
[Parameter()]
[int]
$probonus = 0,
[Parameter()]
[int]
$tests = 500
)
$results = New-Object System.Collections.Generic.List[System.Object]
for ($i = 0; $i -lt $tests ; $i++) {
$Dice = Get-Random -Minimum 1 -Maximum 20
$Result = $Dice + $Bonus + $probonus
if ($Result -ge $DC) {
$results.add($True)
} else {
$results.add($False)
}
}
$Results = $Results.ToArray()
$TotalSuccess = $($Results | Where-Object {$_ -eq $True}).Count
$SuccesRate = ($TotalSuccess / $tests) * 100
Write-Output $SuccesRate"% Success Rate"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment