Skip to content

Instantly share code, notes, and snippets.

@prateekjoshi565
Created November 3, 2019 09:58
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 prateekjoshi565/0746dd4b5dcfedfcf0df2105ee6b39ad to your computer and use it in GitHub Desktop.
Save prateekjoshi565/0746dd4b5dcfedfcf0df2105ee6b39ad to your computer and use it in GitHub Desktop.
def get_randomwalk(node, path_length):
random_walk = [node]
for i in range(path_length-1):
temp = list(G.neighbors(node))
temp = list(set(temp) - set(random_walk))
if len(temp) == 0:
break
random_node = random.choice(temp)
random_walk.append(random_node)
node = random_node
return random_walk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment