Skip to content

Commit

Permalink
Merge pull request #378 from cmu-sei/v8
Browse files Browse the repository at this point in the history
chat job updates
  • Loading branch information
sei-dupdyke authored Jul 18, 2024
2 parents 38a5c90 + c2d1627 commit 7fb427f
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 213 deletions.
24 changes: 24 additions & 0 deletions src/Ghosts.Animator/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ public static string RandomFromProbabilityList(this Dictionary<string, double> l
double sum = 0;
return list.FirstOrDefault(x => r <= (sum += x.Value)).Key;
}

public static int GetWeightedRandomProbabilityResult(this Dictionary<string, int> probabilitySettings)
{
var value = AnimatorRandom.Rand.Next(100);
var cumulativeProbability = 0;

foreach (var probability in probabilitySettings)
{
cumulativeProbability += probability.Value;
if (value < cumulativeProbability)
{
try
{
return Convert.ToInt32(probability.Key);
}
catch
{
throw new Exception("The probabilities are not string, int");
}
}
}

throw new Exception("The probabilities do not sum up to 100.");
}

public static int RandomFromPipedProbabilityList(this Dictionary<string, double> list)
{
Expand Down
Loading

0 comments on commit 7fb427f

Please sign in to comment.