Sortition 0.1.1

dotnet add package Sortition --version 0.1.1
                    
NuGet\Install-Package Sortition -Version 0.1.1
                    
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="Sortition" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sortition" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="Sortition" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sortition --version 0.1.1
                    
#r "nuget: Sortition, 0.1.1"
                    
#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.
#:package Sortition@0.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sortition&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=Sortition&version=0.1.1
                    
Install as a Cake Tool

Sortition (.NET)

Fair, repeatable and verifiable random lotteries for .NET (C#, F#, VB.NET): it picks k of n candidates without replacement, in a way that anyone can repeat and check afterwards. This is a binding of libsortition; it calls the native library through P/Invoke.

Status: experimental (0.1). The interface may change before 1.0. It targets .NET 10.

using Sortition;

string[] people = ["alice", "bob", "carol", "dave"];
ulong seed = Lottery.SeedFromText("my seed");     // publish Lottery.SeedCommit("my seed") before the draw

foreach (var pick in Lottery.DrawItems(people, 2, seed))
    Console.WriteLine(people[pick.Index]);        // dave, bob

The winners depend only on the set of candidates and the seed, not on the order of the list, and they are the same in every language libsortition supports and in its sortition command.

  • Lottery.DrawItems, Lottery.DrawStages, Lottery.ItemFingerprint: candidates (strings or byte arrays) identified by IDs that do not depend on their position; prize stages; the fingerprint of the candidate set.
  • Session and ItemSession: draw in steps, save and restore the state (Save, Load), retry safely with idempotency keys (Draw(k, key)), and hand a sealed state to a browser (Seal, Unseal).
  • Lottery.Draw, DrawText and DrawData return positions in the list as given, so a reordered list gives different winners.

Install

dotnet add package Sortition

The package holds only the .NET code: it also needs the native library (next section).

Finding the native library

The package needs libsortition (libsortition.so, libsortition.dylib or sortition.dll). Get it from the releases page (the lib/ folder of the archive for your platform: Linux, macOS or Windows), or build it from a checkout of the repository with cargo build --release. It is looked up through the LIBSORTITION_PATH environment variable, next to the program, in a target/release folder above the program or the working directory, and then in the usual places of the system.

Build and test

cargo build --release          # in the repository root
dotnet test bindings/dotnet    # the tests read test-vectors/vectors.json

The licenses are MIT or Apache-2.0, at your option.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.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
0.1.1 87 10/26/2026
0.1.0 89 10/26/2026