aryagraph.generators.random.random_regular#

aryagraph.generators.random.random_regular(d: int, n: int, *, seed: int | Generator | None = None, max_tries: int = 1000) → Graph[source]#

Random d-regular simple graph on n nodes (argument order as in networkx).

Pairs degree “stubs” at random and re-pairs only the stubs that would create a loop or duplicate, restarting when that gets stuck (the Steger–Wormald scheme networkx uses). For d > (n-1)/2 the complement of a random (n-1-d)-regular graph is returned, which is much faster and always succeeds. Requires 0 <= d < n and n·d even.

Raises ConvergenceError if max_tries restarts all fail (practically never).