Random Graph Generator
Testing a graph algorithm needs graphs, and hand-drawing them stops being practical at about six nodes. This builds them at whatever density you ask for using the Erdos-Renyi model — every possible edge included with a fixed probability — then measures whether the result actually came out connected rather than assuming it did. At low densities it usually does not, and the tool says so.
What this generator does
Includes each possible edge with the probability you set, which is the standard Erdos-Renyi model. Connectivity is then recomputed from the finished edge list with union-find, so the figure shown is measured rather than claimed — and a graph that came out in separate pieces is reported as such instead of being quietly regenerated.
How to use this tool
- Choose how many nodes and how dense the edges should be.
- Turn on directed or weighted edges if your algorithm needs them.
- Generate, then copy the edge list or the DOT source.
- Add a seed if a test needs the identical graph each run.
Understanding the controls
- How many nodes
- Between 2 and 60. The circular drawing stays readable to about 20; past that the edge list is the useful output.
- Edge density
- The chance each possible edge is included. Connectivity appears quite suddenly as this rises, which is worth seeing.
- Directed and weighted
- Directed edges point one way and are drawn with arrows. Weights are whole numbers in the range you give.
- Seed
- Any word reproduces the same result exactly. Leave it empty and the browser's cryptographic generator is used instead.
Common use cases
- Building test input for a graph algorithm without hand-drawing it
- Showing how connectivity appears suddenly as density rises
- Producing a diagram source you can paste straight into Graphviz
- Generating adjacency data for a teaching exercise
- Checking an algorithm copes with a disconnected input
How this generator works
Each of the n(n-1)/2 possible edges (or n(n-1) when directed) is included independently with the density you set. Connectivity is measured afterwards by union-find, and for directed graphs acyclicity is measured by Kahn's algorithm. Self-loops and duplicate edges are impossible by construction and checked for anyway.
Randomness and fairness
Which edges appear is random; the reported connectivity is not — it is measured from whatever the draw produced. Seeded runs are reproducible and therefore explicitly not cryptographically secure; unseeded runs use the browser's cryptographic generator.
For how randomness is produced across the whole site, see how Generate Random works.
Limitations and good to know
- Erdos-Renyi produces graphs with a very particular degree distribution. Real networks are usually scale-free and look nothing like this.
- The circular layout is deterministic and never overlaps nodes, but it is not a pretty layout — use Graphviz on the DOT export for that.
- Graphs are not stored, so seed anything a test or a diagram needs to reproduce later.
Privacy and your data
The graph is built in your browser from the numbers you set. No edge list, DOT export or seed is transmitted or stored between visits.
Related generators
- DAG GeneratorDirected acyclic graphs where the absence of cycles is structural rather than checked afterwards — for testing schedulers, build systems and topological sorts.
- Minimum Spanning Tree GeneratorWeighted graphs with the cheapest spanning tree found by Kruskal and, at small sizes, confirmed against every other spanning tree.
- Random Tree GeneratorRandom trees with exactly one path between any two nodes — n nodes, n minus 1 edges, no cycles, guaranteed connected.
- Network Topology GeneratorStar, ring, mesh, line and hub-and-spoke topologies drawn to scale, with the edge count each shape forces.
- Test Matrix GeneratorTurn parameters and their values into a test matrix — full factorial, a random sample, or all-pairs coverage in a fraction of the cases.
- Planar Graph GeneratorDraws a random graph that can be laid out with straight lines and no edge crossing another, with the drawing to prove it.