public static Graph Generate(Random random, int numberOfVertices, Func <int, int> density) { PointF[] vertices = new PointF[numberOfVertices]; vertices.FillRandom(random); float[,] edges = new float[numberOfVertices, numberOfVertices]; for (int i = 1; i < numberOfVertices; i++) { int[] indexes = Enumerable.Range(0, i).ToArray(); indexes.Shuffle(random); int lim = random.Next(1, density(i)); for (int j = 0; j < i; j++) { if (j < lim) { edges[i, indexes[j]] = 1; edges[indexes[j], i] = 1; } } } return(new Graph(vertices, edges)); }