public void addRandomEdges(int numOfEdges, int height, int width) {

                // A random bag for storing the possible edges
                RandomBag<Edge> possibleEdges = new RandomBag<Edge>();

                // For every node in the ship
                for (Node n : nodeMap.values()) {

                        // Get nodes that point in each direction
                        Map<Dir, Edge> directions = n.getDirections();

                        // If there is not an edge pointing right
                        if (!edgeMap.containsKey(new Edge(EdgeState.OPEN, n, getNodeAt(n.getRow(), (n.getCol() + 1) % width)).getAdjacent())) {

                                // Add an edge pointing right to the random bag
                                possibleEdges.insert(new Edge(EdgeState.OPEN, n, getNodeAt(n.getRow(), (n.getCol() + 1) % width)));

                        }

                        // If there is not an edge pointing down
                        if (!edgeMap.containsKey(new Edge(EdgeState.OPEN, n, getNodeAt((n.getRow() + 1) % height, n.getCol())).getAdjacent())) {

                                // Add an edge pointing down to the random bag
                                possibleEdges.insert(new Edge(EdgeState.OPEN, n, getNodeAt((n.getRow() + 1) % height, n.getCol())));

                        }
                }

                // Remove a given number of edges from the bag and add them to
                // the ship
                for (int i = 0; i < numOfEdges; i++) {

                        try {
                                // Add the edge to the ship
                                addEdge(possibleEdges.extract());
                        } catch (Exception e) {
                                throw new IllegalStateException("Cannot add that many edges");
                        }
                }

        }