Random Numbers, Random Walks, and Diffusion

Are things set up right?

If your account is set up right, typing
        Random
should produce a terse description of all the options of the random number utility. Typing
        man Random
should generate the manual page for the random number generator, which is a bit more descriptive. You can do the same for PlotAtoms and our other tools. If this doesn't work, you don't have LASSPTools in your path (or MANPATH). If you're not in physics at Cornell, this likely means that you'll need to install some of them. You can use the mouse to "cut and paste" from this HTML page to avoid typing. It should go fast...

Sums of Random Variables

Random Number Generators

The routine "Random" generates random numbers.
	Random -objects 1

	Random -objects 1 -seed 2345

   	Random -objects 10
The vertical bar "|" is a pipe: it connects the output of one program to the input of the next. The utility "histogram" will bin the random numbers into equally spaced intervals:
	Random -objects 1000 | histogram
The output of histogram is a bunch of boxes, which are meant to be plotted. "xmgr" is a rather nice plotting package. It normally reads in files, so we have to tell it we're reading our curve from a pipe:
	Random -objects 1000 | histogram | xmgr -source stdin

Different distributions

	Random -objects 1000 -flat -3 5 | histogram | xmgr -source stdin
	Random -objects 1000 -gaussian 2. | histogram | xmgr -source stdin
	Random -objects 1000 -exp 17 | histogram | xmgr -source stdin
and different generators:
	Random -objects 1000 -exp 17 -griff | histogram | xmgr -source stdin

Random Walks

Random walk in one dimension

	Random -objects 10 -flat -0.5 0.5
random walk ("accumulate objects" sums the random numbers):
	Random -objects 10 -flat -0.5 0.5 -accumulate objects
plot random walk ("\" continues onto the next line)
	Random -objects 3000 -flat -0.5 0.5 -accumulate objects \
	| xmgr -source stdin

Random walk in two dimensions: random 2x1 matrix

	Random -objects 10 -matrix 1 2 -accumulate objects -flat -0.5 0.5  
We get (x,y) pairs for the steps of the drunkard's walk! We can use PlotAtoms to make an animation. PlotAtoms takes (x,y) pairs from the standard input, and plots them. Try typing
	PlotAtoms
	1 2
	2 4
	4 1

(ending with two "returns"): this should put three spheres at the given locations. Frames in the animation are separated by blank lines in the input: "Random" puts blank lines between objects, so
	Random -objects 1000 -matrix 1 2 -accumulate objects -flat -0.5 0.5 \
	| PlotAtoms -xmin -5 -xmax 5 -ymin -5 -ymax 5
should give you a random walk animation. By adding rows to the matrix
	Random -objects 3 -matrix 5 2 -accumulate objects -flat -0.5 0.5 
we can have several atoms flying around:
	Random -objects 100 -matrix 10 2 -accumulate objects -flat -0.5 0.5 \
	| PlotAtoms -xmin -3 -xmax 3 -ymin -3 -ymax 3
more, smaller atoms make for a diffusing cloud:
	Random -objects 200 -matrix 300 2 -accumulate objects -flat -0.5 0.5 \
	| PlotAtoms -xmin -5 -xmax 5 -ymin -5 -ymax 5 -radius 6 -color yellow
Measure the radius as a function of time: see that it grows as sqrt(t). What is the diffusion constant?

Random walk (length 10, here done by accumulating columns):

	Random -objects 1 -matrix 10 1 -index -accumulate cols -flat -0.5 0.5 
squared distance of random walk:
	Random -objects 1 -matrix 10 1 -index -accumulate cols \
	-flat -0.5 0.5 -square  
plot squared distance of longer walk:
	Random -objects 1 -matrix 1000 1 -index -accumulate cols \
	-flat -0.5 0.5 -square  | xmgr -source stdin 
lots of fluctuations! Plot five
	Random -objects 5 -matrix 1000 1 -index -accumulate cols \
	-flat -0.5 0.5 -square  | xmgr -source stdin 
See how average works on five short walks:
	Random -objects 5 -matrix 10 1 -index -accumulate cols \
	-flat -0.5 0.5 -square  | xmgr -source stdin 

	Random -objects 5 -matrix 10 1 -index -accumulate cols \
	-flat -0.5 0.5 -square -average | xmgr -source stdin 
and then plot the average of 100 long walks:
	Random -objects 100 -matrix 1000 1 -index -accumulate cols \
	-flat -0.5 0.5 -square -average | xmgr -source stdin 

Sums of Random Variables: Convolutions and the Central Limit Theorem

Histograms after zero and one step: histogram binsize 0.05. We need to do some fiddling to get an animation: pre_gr does that for us.
	Random -objects 2 -flat -0.5 0.5 -matrix 3000 1 -accumulate objects \
	| histogram -sep -s 0.1 \
	| pre_gr xmgr.animate \
	| xmgr -pipe
histograms after first five steps
	Random -objects 5 -flat -0.5 0.5 -matrix 1000 1 -accumulate objects \
	| histogram -sep -s 0.1 \
	| pre_gr xmgr.animate \
	| xmgr -pipe
Click the A/S button to see the whole range.

Links Back

Diffusion: The Problem Set
Cornell Physics Undergrad Home Page
Entertaining Science done at
LASSP.

Last modified: August 29, 1994

Jim Sethna, sethna@lassp.cornell.edu

Statistical Mechanics: Entropy, Order Parameters, and Complexity, now available at Oxford University Press (USA, Europe).