Kernel: Python 2 (SageMath)
In [1]:
import random #import a library of random commands x = 0 #sets the variable k = [] #creates an empty list for j in range(0,99): #first loop : begins the programm for a new particule each time x = 0 #reset the initial position for each particule to 0 for i in range(0,99): #second loop : begins the movement of the particule, #going left or right d = random.randint(0,1) #i takes the value 1 or 0 randomly if d == 0: x = x-1 #if d == 0, particule goes left k.append(x) #adds the value to the table else: x = x+1 #if d == 1, particule goes right k.append(x) #adds the value to the table import matplotlib.pyplot as plt #import the library to plot plt.xlabel('Position') #lables the x-absciss with a chosen name plt.ylabel('Iterations') #lables the y-absciss with a chosen name plt.title('Position of a 100 particules and the iteration of each') #gives a title #to the graph plt.hist(k, bins=30) #plots the graph as a histogram taking the list in account, #and the number of bins chosen.