Professional Documents
Culture Documents
Random Numbers - A Note
Random Numbers - A Note
Distributions
Basic generator is uniform on [0,m]. Scale to
make uniform on [0,1]
To generate other distributions, use
p(y) dy = p(x) dx
Hence
dx
p ( y ) = p( x)
dy
Generators
Many random number generators:
f95 intrinsic functions
call random_number (harvest) . Uniform on [0,1], harvest
may be array
call random_seed (size, put, get)
30/10/2007
How random?
We guarantee that each number is random
individually, but we dont guarantee that more
than one of them is random (see Press et al
p193)
In practice, need to make a good choice of c and
m. (see next slide).
30/10/2007
Variance of ran1
Simulate normal distribution by adding 12 samples and
subtracting mean
30/10/2007
Various generators
30/10/2007
About software
How can it go wrong?
1. Fundamentally
Wrong physics.
Numerical methods
Instability
2. Methodologically
Wrong program (bugs)
Wrong spec (What is the answer to the ultimate
question?)
Too late or slow to be useful
30/10/2007
30/10/2007
General advice
It is easy to write a good computer programme
BUT it is even easier to write a bad computer programme
The difference between doing it well and doing it badly is
basically a matter of:
Thinking about the problem and designing the computer
programme first.
Care and attention to detail when writing the code.
Testing everything you do in bits which are as small as
possible (of the order of 5 lines of code).
30/10/2007
How?
Carefully!
Think first, program later
Be prepared to throw one away
Document, document, document
Use comments, choose variable names carefully...
30/10/2007