The built-in NetworkX implementations of traversal functions often provide hooks for such features. For example, `nx.generic_bfs_edges` has a `neighbors` parameter that accepts a callable to allow you to control how neighboring nodes are accessed. You could use this feature to access nodes in a random order with something like:
```
>>> G = nx.star_graph(5) # Example input
>>> list(nx.generic_bfs_edges(G, 0)) # default neighbor order
[(0, 1), (0, 2), (0, 3), (0, 4), (0, 5)]
>>> def randomized(n):
... neighbors = list(G[n])
... random.shuffle(neighbors)
... return neighbors
>>> list(nx.generic_bfs_edges(G, 0, neighbors=randomized)) # randomized node order
[(0, 3), (0, 5), (0, 4), (0, 1), (0, 2)]
```
This doesn't necessarily address your performance concerns, but I just thought it was worth drawing this feature to your attention!
~Ross