public static int GetBoundedRnd(int low, int high) { if (low > high) { Algorithms.Swap(ref low, ref high); } return(low + GetRandom(high - low + 1)); }
public void Test_SwapT() { int x1 = 5; int x2 = 11; Assert.AreEqual(5, x1); Assert.AreEqual(11, x2); Algorithms.Swap(ref x1, ref x2); Assert.AreEqual(5, x2); Assert.AreEqual(11, x1); }
public static bool IsValueBetween(double value, double lowLimit, double topLimit, bool includeLimits) { if (lowLimit > topLimit) { Algorithms.Swap(ref lowLimit, ref topLimit); } if (!includeLimits) { lowLimit += 0.000001; topLimit -= 0.000001; } return(value >= lowLimit && value <= topLimit); }
public static bool IsValueBetween(int value, int lowLimit, int topLimit, bool includeLimits) { if (lowLimit > topLimit) { Algorithms.Swap(ref lowLimit, ref topLimit); } if (!includeLimits) { lowLimit++; topLimit--; } return(value >= lowLimit && value <= topLimit); }