12.07.2015 Views

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

monte carlo simulations (nonthermal) 111250200y1501005000 50 100 150 200 250x0 50 100 150 200 250xFigure 5.1 Left: A plot of successive random numbers (x, y)=(r i , r i + 1 ) generated with adeliberately “bad” generator. Right: A plot generated with the library routine drand48.r 2 =(4× 3+1)mod 9=13mod 9=rem 13 9r 3 =(4× 4+1)mod 9=17mod 9=rem 17 9r 4 =(4× 8+1)mod 9=33mod 9= rem 33 9=4, (5.3)=8, (5.4)=6, (5.5)r 5−10 =7, 2, 0, 1, 5, 3. (5.6)We get a sequence of length M =9, after which the entire sequence repeats. If wewant numbers in the range [0, 1], we divide the r’s by M =9:0.333, 0.444, 0.889, 0.667, 0.778, 0.222, 0.000, 0.111, 0.555, 0.333.This is still a sequence of length 9 but is no longer a sequence of integers. If randomnumbers in the range [A, B] are needed, you only need to scale:x i = A +(B − A)r i , 0 ≤ r i ≤ 1, ⇒ A ≤ x i ≤ B. (5.7)As a rule of thumb: Before using a random-number generator in your programs, youshould check its range and that it produces numbers that “look” random.Although not a mathematical test, you should always make a graphical displayof your random numbers. Your visual cortex is quite refined at recognizing patternsand will tell you immediately if there is one in your random numbers. For instance,Figure 5.1 shows generated sequences from “good” and “bad” generators, and it isclear which is not random (although if you look hard enough at the random points,your mind may well pick out patterns there too).−101<strong>COPYRIGHT</strong> <strong>2008</strong>, PRINCET O N UNIVE R S I T Y P R E S SEVALUATION COPY ONLY. NOT FOR USE IN COURSES.ALLpup_06.04 — <strong>2008</strong>/2/15 — Page 111

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!