ToolBX.CoinFlip
3.0.0
dotnet add package ToolBX.CoinFlip --version 3.0.0
NuGet\Install-Package ToolBX.CoinFlip -Version 3.0.0
<PackageReference Include="ToolBX.CoinFlip" Version="3.0.0" />
paket add ToolBX.CoinFlip --version 3.0.0
#r "nuget: ToolBX.CoinFlip, 3.0.0"
// 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
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 T
s.
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 | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
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 | 3,961 | 5/9/2024 |