ToolBX.CoinFlip 3.0.0

dotnet add package ToolBX.CoinFlip --version 3.0.0
NuGet\Install-Package ToolBX.CoinFlip -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="ToolBX.CoinFlip" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ToolBX.CoinFlip --version 3.0.0
#r "nuget: ToolBX.CoinFlip, 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 ToolBX.CoinFlip as a Cake Addin
#addin nuget:?package=ToolBX.CoinFlip&version=3.0.0

// Install ToolBX.CoinFlip as a Cake Tool
#tool nuget:?package=ToolBX.CoinFlip&version=3.0.0

CoinFlip

What is it?

Adds Coin.Flip() methods for easy, straightforward two-result randoms.

Returning a random true/false

Result will be either true or false.

var result = Coin.Flip();

Returning a random out of two values

The method is generic and will take any type, not just string.

var result = Coin.Flip("Rambo", "Snake");

Alternatively, you can use FlipOrDefault if you only need to return one value or "nothing".

var result = Coin.FlipOrDefault("Snake");

Executing random delegates

You can pass Func<T> objects to it as well if your logic is more than just returning plain old Ts.

var result = Coin.Flip(() => { ... }, () => { ... });

Alternatively, you can use FlipOrDefault if you only need to execute one or "nothing".

var result = Coin.FlipOrDefault(() => { ... });

If you need to execute code that doesn't return, you can use Action delegates.

Coin.Flip(() => { DestroyTheWorld }, () => SaveTheWorld);

Or if you only want one of those to execute or for nothing to happen.

Coin.Flip(() => { DestroyTheWorld });

Why use this?

It was written mostly with unit testing in mind but it can be used for basically any purpose where you need to have a random result between two options.

This is a super lightweight library that does almost nothing and has zero dependencies.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ToolBX.CoinFlip:

Package Downloads
ToolBX.Dummies

A lightweight object generation framework for unit testing purposes

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 80 5/9/2024