Skip to content

Instantly share code, notes, and snippets.

@stephengruppetta
Created June 25, 2023 08:44
Show Gist options
  • Save stephengruppetta/fd55cd3bb8bd46e193106b75c940be56 to your computer and use it in GitHub Desktop.
Save stephengruppetta/fd55cd3bb8bd46e193106b75c940be56 to your computer and use it in GitHub Desktop.
import random
class RandomWalk:
def __init__(self, iterable):
self.values = list(iterable)
def __iter__(self):
return RandomWalkIterator(self)
class RandomWalkIterator:
def __init__(self, random_walk):
self.random_walk = random_walk
self.random_indices = list(
range(len(random_walk.values))
)
random.shuffle(self.random_indices)
self.idx = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment