forked from pplab/quantum-walk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomWalkOnRing.py
executable file
·37 lines (33 loc) · 972 Bytes
/
RandomWalkOnRing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/python3
# This program is to simulate classical random walks on a line.
# All walkers start at position 0 and do a random choice to walk left (position - 1) or right (position + 1).
# Collect all the walkers' position at every time.
import random
random.seed()
# set walkers' number
nWalker=1000
# set total walking time
totalTime=2000
# set ring size
ringSize=100
# set initial condition: time=0; all walker are at position 0
position=[0 for i in range(nWalker)]
amount=[0 for i in range(ringSize)]
amount[0]=nWalker
# do simulation
for time in range(0,totalTime):
for walker in range(0,nWalker):
p=position[walker]
amount[p]-=1
step=random.choice([-1,1])
p+=step
if(p<0):
p+=ringSize
if(p>=ringSize):
p-=ringSize
position[walker]=p
#count the number of positions
amount[p]+=1
for p in range(0,ringSize):
print(amount[p],end='\t')
print()