Skip to content

Instantly share code, notes, and snippets.

@RobertTalbert
Created February 2, 2017 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertTalbert/9561e888ba0db73d843c887a1d15c766 to your computer and use it in GitHub Desktop.
Save RobertTalbert/9561e888ba0db73d843c887a1d15c766 to your computer and use it in GitHub Desktop.
Code for Guided Practice 7, MTH 325
# Import networkx
import networkx as nx
# Import two functions from the "random" library:
# randint(a,b) generates a random integer between a and b
# random() generates a random floating point number between 0 and 1
from random import random, randint
# Generates 5 random graphs with random numbers of nodes and
# connection probabilities, and prints off their dictionaries.
for i in range(5):
n = randint(2, 10)
p = random()
g = nx.random_graphs.gnp_random_graph(n,p)
print(nx.to_dict_of_lists(g))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment