Skip to content

Instantly share code, notes, and snippets.

@jschaub30
Created May 4, 2015 17:53
Show Gist options
  • Save jschaub30/e55df923838cd9839f2a to your computer and use it in GitHub Desktop.
Save jschaub30/e55df923838cd9839f2a to your computer and use it in GitHub Desktop.
Python script to generate random edge list of graph based on nodes and edges
#!/usr/bin/python
import sys
import random
def main(argList):
if '-edges' in argList:
a = argList.index('-edges')
edges = int(argList[a+1])
else:
edges = 512
if '-nodes' in argList:
a = argList.index('-nodes')
nodes=int(argList[a+1])
else:
nodes = 128
if '-seed' in argList:
a = argList.index('-seed')
seed = int(argList[a+1])
else:
seed = 1048576
for i in genPair(nodes,edges,seed):
print i
def genPair(nodes, edges, seed):
graph = set()
nodeList = range(nodes)
random.seed(seed)
while len(graph) < edges:
pair = "\"%s\",\"%s\",-" % (str(random.choice(nodeList)), str(random.choice(nodeList)))
graph.add(pair)
return graph
if __name__ == '__main__':
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment