Friday, October 17, 2014

Randomize boolean method in C#

I just saw this slick little trick in a Xamarin class.  Instructor needed to have a sample class randomly return a true or false. 

This is so simple:

public bool IsTrue()
{
return new Random().Next() % 2 == 0;
}

No comments:

Post a Comment