Don’t constrain the problem to a specific rendering platform.
It’s a graph, all there is are node and edges. They can be rendered however you please, generating the graph has nothing to do with it.
Maybe something like:
int numNodes = (int) (Math.random() * MAX_NODES);
int numEdges = (int) (/* suitable expression*/);
List<Point> nodes = new ArrayList<>(numNodes);
List<Line> edges = new ArrayList<>(numEdges);
for (int i = 0; i < numNodes; i++)
nodes.add(new Point((int) (Math.random() * MAX_X), (int) (Math.random() * MAX_Y)));
// this gets more complicated if you want the graphs
// to be simple, or have other specific properties.
for (int i = 0; i < numEdges; i++) {
Point p1 = nodes.get((int) (Math.random() * numNodes));
Point p2 = nodes.get((int) (Math.random() * numNodes));
edges.add(new Line(p1, p2));
}
Then you can render it just by iterating over edges
and nodes
and rendering lines and circles.
Note that loops must either be eliminated (while p1 == p2, try again, etc.) or handled as a special case in rendering, as currently they will not be visible using just a drawLine() like primitive.