Here's one way to simulate self-avoiding random walks in Python:
main.py1024 chars32 linesThe simulate_saw function takes two arguments: dim, the number of dimensions of the walk, and steps, the number of steps in the walk. It returns a dim x steps array containing the coordinates of the walk.
To generate a 2D self-avoiding random walk with 1000 steps, for example, you could use:
main.py32 chars2 lines
This will return a 2 x 1000 array where the first row contains the x-coordinates and the second row contains the y-coordinates of the walk.
gistlibby LogSnag