How to flip a coin in C# or VB.NET

To flip a coin in C# or VB.NET you just need to use this extension method on a instance of random.

Extension Method C#

public static bool FlipCoin(this Random rand)
{
    return rand.Next(2) == 0;
}

Extension Method VB.NET

<System.Runtime.CompilerServices.Extension> _
Public Shared Function FlipCoin(rand As Random) As Boolean
	Return rand.Next(2) = 0
End Function

Please Share us:
Please rate this snippet

One thought on “How to flip a coin in C# or VB.NET

Leave a Reply