public static void GenerateTemplateDb( int givenCylinderDbCount, int givenTemplateDbCount, int givenCylinderCellsCount) { cylinderDbCount = givenCylinderDbCount; templateDbCount = givenTemplateDbCount; cylinderCellsCount = givenCylinderCellsCount; db = new Cylinder[cylinderDbCount]; templateIndices = new int[cylinderDbCount]; templateDbLengths = new int[templateDbCount]; for (int i = 0; i < cylinderDbCount; i++) { Cylinder curCylinder = new Cylinder(); // For further randomness (so that cylinders don't have very similar norms) double curThreshold = rnd.NextDouble(); uint[] curCylinderValues = new uint[cylinderCellsCount]; for (int j = 0; j < cylinderCellsCount; j++) { double x = rnd.NextDouble(); curCylinderValues[j] = x < curThreshold ? (uint)0 : 1; // Cast necessary? o_o } curCylinder.Values = curCylinderValues; curCylinder.Angle = rnd.NextDouble() * 2 * Math.PI; curCylinder.Norm = CylinderHelper.CalculateCylinderNorm(curCylinder.Values); db[i] = curCylinder; } // Thresholds again for further randomness (not a uniform distribution between templates) double[] templateThresholds = new double[templateDbCount - 1]; for (int i = 0; i < templateDbCount - 1; i++) { templateThresholds[i] = rnd.NextDouble(); } for (int i = 0; i < cylinderDbCount; i++) { double x = rnd.NextDouble(); int curTemplateIndex = 0; for (int j = 0; j < templateDbCount - 1; j++) { if (x > templateThresholds[j]) { curTemplateIndex++; } } templateIndices[i] = curTemplateIndex; templateDbLengths[curTemplateIndex]++; } }