A concise C# library for effortless random selection of items from a list, each with its own probability. Perfect for scenarios requiring diverse likelihoods in a simple and efficient package.
$ dotnet add package AndyCosta.WeightedRandomA concise C# library for effortless random selection of items from a list, each with its own probability. Perfect for scenarios requiring diverse likelihoods in a simple and efficient package.
Various examples have been provided in this repo using CLI, WPF, etc.
In a nutshell:
Option<T>.
Value of type T and an integer representing its Weight.new Option<char>('A', 10) creates an Option for the character A with a weight of 10.WeightedRandomizer<T>.
System.Random is usedNext() and consume the returned value however you wish.var options = new []
{
new Option<char>('A', 10),
new Option<char>('B', 30),
new Option<char>('C', 10),
};
var weightedRandom = new WeightedRandomizer<char>(options);
Option<char> selection = weightedRandom.Next();
This project is licensed under the MIT License - see the LICENSE.md file for details