/// <summary> /// Method choice random dimension(proportional to len) and random value for split /// </summary> void CreateSplitData() { // Get sum of all dimension and choice random number // All dimensions going one after one decimal splitValue = RandomTools.RandomDecimal(0, boxLen.Sum()); decimal sum = 0; short i = 0; // Figure out in that dimension is splitValue(after cicle it will be i-1) do { sum += boxLen[i]; i++; } while (sum < splitValue); // i==1 mean that splitValue in 0 dimension, simple calculation if (i == 1) { splitValue = boxMin[0] + splitValue; SplitDimension = 0; } // i > 1, to get split value in current dimension // need cut off all previos dimensions(thay going one after one) from sum // and add to start position(min boundiong box) else { sum -= boxLen[i - 1]; splitValue = boxMin[i - 1] + (splitValue - sum); SplitDimension = (byte)(i - 1); } SplitValue = splitValue; }
public void Test_RandomDecimal_CheckInterval() { var a1 = RandomTools.RandomDecimal(0, 0.0000003M); var a2 = RandomTools.RandomDecimal(0, 1.0000003M); var a3 = RandomTools.RandomDecimal(10.1M, 5250.023M); var a4 = RandomTools.RandomDecimal(-10.2M, 9.03M); var rez1 = ((a1 >= 0) && (a1 < 0.000003M)); var rez2 = ((a2 >= 0) && (a2 < 1.0000003M)); var rez3 = ((a3 >= 10.1M) && (a3 < 5250.023M)); var rez4 = ((a4 >= -10.2M) && (a4 < 9.03M)); Assert.IsTrue(rez1); Assert.IsTrue(rez2); Assert.IsTrue(rez3); Assert.IsTrue(rez4); }