RoundRobin 2.2.1

.NET Standard 2.0
dotnet add package RoundRobin --version 2.2.1
NuGet\Install-Package RoundRobin -Version 2.2.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="RoundRobin" Version="2.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RoundRobin --version 2.2.1
#r "nuget: RoundRobin, 2.2.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install RoundRobin as a Cake Addin
#addin nuget:?package=RoundRobin&version=2.2.1

// Install RoundRobin as a Cake Tool
#tool nuget:?package=RoundRobin&version=2.2.1

Round Robin implementation in C#

Alt Text

Round Robin is a very simple but in the same time very useful algorithm, but there is no native implementation in C#. So here is a simple but powerful and thread-safe implementation of the Round Robin algorithm in C#.

Nuget

Usage

//installation
dotnet add package RoundRobin
Install-Package RoundRobin
var roundRobinList = new RoundRobinList<int>(
    new List<int>{
        1,2,3,4,5
    }
);

for (var i = 0; i < 8; i++)
{
    Write($"{roundRobinList.Next()},");
}

//result
//1,2,3,4,5,1,2,3,

Also you can increase/decrease the weights, by doing so you will be able to increase/decrease the priority of an element in the Round Robin list

var roundRobinList = new RoundRobinList<int>(
    new List<int>{
        1,2,3,4,5
    }
);

//the weight of the element 1 will be increase by 2 units
roundRobinList.IncreaseWeight(element:1, amount:2);

for (var i = 0; i < 10; i++)
{
    Write($"{roundRobinList.Next()},");
}

//result
//1,1,1,2,3,4,5,1,1,1

Also you can set the weights during the initialization

var roundRobinList = new RoundRobinList<int>(
    new List<int>{
        1,2,3,4,5
    },new int[]{0,1,0,0,0}
);

for (var i = 0; i < 10; i++)
{
    Write($"{roundRobinList.Next()},");
}

//result
//1,2,2,3,4,5,1,2,2,3

Enjoy coding 😃

Product Versions
.NET net5.0 net5.0-windows 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
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.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
2.2.1 30,698 3/13/2022
2.1.1 331 2/16/2022
2.1.0 19,472 8/17/2021
2.0.2 249 2/16/2022
2.0.1 25,253 1/27/2021
2.0.0 31,363 1/13/2020
1.0.0 448 1/12/2020