Adds Coin.Flip() methods for easy, straightforward two-result randoms.
Result will be either true
or false
.
var result = Coin.Flip();
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");
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 });
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.