implement random-traversal function