RandomSelection 3.0.0
dotnet add package RandomSelection --version 3.0.0
NuGet\Install-Package RandomSelection -Version 3.0.0
<PackageReference Include="RandomSelection" Version="3.0.0" />
paket add RandomSelection --version 3.0.0
#r "nuget: RandomSelection, 3.0.0"
// Install RandomSelection as a Cake Addin
#addin nuget:?package=RandomSelection&version=3.0.0
// Install RandomSelection as a Cake Tool
#tool nuget:?package=RandomSelection&version=3.0.0
RandomSelection
The inspiration for this library came from watching people who were entered into supposed random prize drawings win multiple times while others were consistently not picked. RandomSelection is designed to take in entries, with the option to give some entries a higher chance at being selected, and then return one or more selectees. It utilizes System.Security.Cryptography to ensure a higher quality random number is used for shuffling the data and selecting winners.
Examples
- Create an instance of the Selector class, add two items representing employees and then selects one employee at random.
var selector = new Selector<string>();
selector.TryAddItem("m0392", "Doe, John", 1);
selector.TryAddItem("m0392", "Moe, Jane", 1);
var winner = selector.RandomSelect();
- Create an instance of the Selector class, add five items where the third entry has two more entries than the others. Then two winners are selected
var selector = new Selector<string>();
selector.TryAddItem("jen", "jen", 1);
selector.TryAddItem("michael", "michael", 1);
selector.TryAddItem("staci", "staci", 3);
selector.TryAddItem("dave", "dave", 1);
selector.TryAddItem("leslie", "leslie", 1);
var winners = selector.RandomSelect(2);
Product | Versions |
---|---|
.NET | net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows |
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Updated to .NET 6, changed to use RandomNumberGenerator, and added unit tests.