Skip to content

Instantly share code, notes, and snippets.

@Omig12
Last active March 4, 2017 16:12
Show Gist options
  • Save Omig12/4b7be2a2b0b1994e858fa4ed1037583a to your computer and use it in GitHub Desktop.
Save Omig12/4b7be2a2b0b1994e858fa4ed1037583a to your computer and use it in GitHub Desktop.
Pseudo-Random Pseudo-Graph Generator
# n parameter:
# represents the ammount of nodes desired in the graph.
from random import *
def rand_graph(n=2):
randgraph = {}
Nodes = [x for x in range(n)]
shuffle(Nodes)
Edges = [(x,randint(0,n)) for x in Nodes]
for i in Nodes:
randgraph[i] = {y for x in Edges if i in x for y in x if y != i }
return randgraph
print (rand_graph())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment