-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Labels
coreIssues related to the "Core" moduleIssues related to the "Core" moduleenhancementNew feature or requestNew feature or requestroadmapFeature of the roadmapFeature of the roadmapvNextIssues planed for the next versionIssues planed for the next version
Description
Enhancement
Add the possibility to generate a randomly selected value based on the specified probabilities.
Other informations
using System;
using System.Collections.Generic;
public static class RandomValueGenerator
{
public static T GetRandomValue<T>(Dictionary<T, double> probabilities)
{
double totalProbability = 0.0;
foreach (double probability in probabilities.Values)
{
totalProbability += probability;
}
if (totalProbability != 1.0)
{
throw new ArgumentException("The sum of probabilities must be 1.");
}
double randomValue = new Random().NextDouble();
double cumulativeProbability = 0.0;
foreach (T value in probabilities.Keys)
{
cumulativeProbability += probabilities[value];
if (randomValue < cumulativeProbability)
{
return value;
}
}
throw new Exception("An unexpected error occurred while selecting a random value.");
}
}Metadata
Metadata
Assignees
Labels
coreIssues related to the "Core" moduleIssues related to the "Core" moduleenhancementNew feature or requestNew feature or requestroadmapFeature of the roadmapFeature of the roadmapvNextIssues planed for the next versionIssues planed for the next version