RandomSelection 3.0.0

dotnet add package RandomSelection --version 3.0.0                
NuGet\Install-Package RandomSelection -Version 3.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RandomSelection" Version="3.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RandomSelection --version 3.0.0                
#r "nuget: RandomSelection, 3.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

  1. 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();
  1. 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 Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last updated
3.0.0 352 11/27/2022
2.0.1 478 1/2/2021
2.0.0 574 11/7/2019

Updated to .NET 6, changed to use RandomNumberGenerator, and added unit tests.