I only know how I can generate a random boolean value (true/false). The default probability is 50:50
But how can I generate a true false value with my own probability? L
Here is an extension method that will provide a random bool with specified probability (in percentage) of being true;
public static bool NextBool(this Random r, int truePercentage = 50)
{
return r.NextDouble() < truePercentage / 100.0;
}
you can use this like
Random r = new Random();
r.NextBool(); // returns true or false with equal probability
r.NextBool(20); // 20% chance to be true;
r.NextBool(100); // always return true
r.NextBool(0); // always return false