public static void AddRandomEdge(CircleGraph graph, Node node, double[] vars) { List <Node> others = new List <Node>(); if (node.ConnectedTo(graph.Adjacent(node, 1))) { others.Add(graph.Adjacent(node, 1)); } if (node.ConnectedTo(graph.Adjacent(node, -1))) { others.Add(graph.Adjacent(node, -1)); } if (node.ConnectedTo(graph.Adjacent(node, 2))) { others.Add(graph.Adjacent(node, 2)); } if (node.ConnectedTo(graph.Adjacent(node, -2))) { others.Add(graph.Adjacent(node, -2)); } Node rand = null; do { rand = graph.RandomNode(); }while (rand == node || others.Contains(rand)); others.Add(rand); node.To(others[randgen.Next(others.Count)], 1.0); }