Created
May 4, 2015 17:53
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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