title: How to generate a randomized path through nodes in a network
body: <p>I have a regular network of <em>N</em> nodes connected together and I want to generate a path that visits <em>n</em> nodes exactly once. I also require that there's some degree of randomness in the path so that I'm able to create different paths given the same starting node.</p>
  
  <p><img src="https://i.stack.imgur.com/9KDWh.png" alt="See the problem illustration here."></p>
  
  <p>My current solution is to pick a random starting node and then randomly visit an adjacent node, and repeat until I visit <em>n</em> nodes. Whenever the path does not allow me to visit <em>n</em> nodes, I backtrack to attempt through another node.</p>
  
  <p>When the number of nodes and connections is small this works fine, however when these are increased and <em>n</em> approaches <em>N</em> it takes very long to find a solution if at all.</p>
  
  <p>Could you suggest alternative approaches that are guaranteed to succeed in reasonable time?</p>