PROGRAM box ! simulation of the particles in a box problem CALL initial(N,tmax) CALL move(N,tmax) ! move particles through hole END SUB initial(N,tmax) RANDOMIZE INPUT prompt "number of particles = ": N LET tmax = 20*N SET WINDOW -0.01*tmax,1.01*tmax,-0.01*N,1.01*N CLEAR BOX LINES 0,tmax,0,N SET COLOR "blue" PLOT 0,0.5*N;tmax,0.5*N ! equilibrium value END SUB SUB move(N,tmax) LET nleft = N ! initially all particles on left side SET COLOR "red" FOR t = 1 to tmax ! generate random number and move particle LET r = int(N*rnd) + 1 IF r <= nleft then LET nleft = nleft - 1 ELSE LET nleft = nleft + 1 END IF PLOT t,nleft; NEXT t END SUB