https://github.com/hrkings/weightedrandomselectionlib
A efficient weighted random selection library
https://github.com/hrkings/weightedrandomselectionlib
gacha random selection selector weighted weights
Last synced: 3 months ago
JSON representation
A efficient weighted random selection library
- Host: GitHub
- URL: https://github.com/hrkings/weightedrandomselectionlib
- Owner: HRKings
- License: gpl-3.0
- Created: 2019-10-08T01:19:28.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-01-15T06:42:21.000Z (over 3 years ago)
- Last Synced: 2024-12-27T13:23:08.254Z (5 months ago)
- Topics: gacha, random, selection, selector, weighted, weights
- Language: C#
- Homepage:
- Size: 86.9 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Weighted Random Selection Lib
Weighted Random Selection Lib is a library implementation of a weighted random selection algorithm built on top of .NET 5 to reach almost any platform
The implementation uses efficient algorithms to deliver fast selections (like Binary Search)
## Example
Bellow is an example of how the library can be usedThe code will select 10 of the available choices based on their weights and display one by line on the console
```c#
using WeightedRandomSelectionLib;class Program {
static void Main (string[] args)
{
WeightedRandomSelector selector = new WeightedRandomSelector();selector.Add("Choice 1", 0.8);
selector.Add("Choice 2", 15.0);
selector.Add("Choice 3", 62.21);
selector.Add("Choice 4", 32.5);
selector.Add("Choice 5", 70.0);foreach (string i in selector.SelectMultiple (10))
{
Console.WriteLine(i);
}
}
}
```Obs.: You can also add a WeightedItem collection for more control (or to add more than one item at time), you can also pass this collection in the constructor if you want to.