This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.


random_degree_sequence_graph(sequence, seed=None, tries=10)[source]

Returns a simple random graph with the given degree sequence.

If the maximum degree \(d_m\) in the sequence is \(O(m^{1/4})\) then the algorithm produces almost uniform random graphs in \(O(m d_m)\) time where \(m\) is the number of edges.

  • sequence (list of integers) – Sequence of degrees
  • seed (integer, random_state, or None (default)) – Indicator of random number generation state. See Randomness.
  • tries (int, optional) – Maximum number of tries to create a graph

G – A graph with the specified degree sequence. Nodes are labeled starting at 0 with an index corresponding to the position in the sequence.

Return type:


  • NetworkXUnfeasible – If the degree sequence is not graphical.
  • NetworkXError – If a graph is not produced in specified number of tries

See also

is_graphical(), configuration_model()


The generator algorithm [1] is not guaranteed to produce a graph.


[1]Moshen Bayati, Jeong Han Kim, and Amin Saberi, A sequential algorithm for generating random graphs. Algorithmica, Volume 58, Number 4, 860-910, DOI: 10.1007/s00453-009-9340-1


>>> sequence = [1, 2, 2, 3]
>>> G = nx.random_degree_sequence_graph(sequence)
>>> sorted(d for n, d in G.degree())
[1, 2, 2, 3]