GenerateRandomSearch

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

  1. Choose how many nodes and how dense the edges should be.
  2. Turn on directed or weighted edges if your algorithm needs them.
  3. Generate, then copy the edge list or the DOT source.
  4. 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.