02.05.2014 Views

PENELOPE 2003 - OECD Nuclear Energy Agency

PENELOPE 2003 - OECD Nuclear Energy Agency

PENELOPE 2003 - OECD Nuclear Energy Agency

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1.2. Random sampling methods 7<br />

Table 1.1: Fortran77 random number generator.<br />

C *********************************************************************<br />

C<br />

FUNCTION RAND<br />

C *********************************************************************<br />

FUNCTION RAND(DUMMY)<br />

C<br />

C This is an adapted version of subroutine RANECU written by F. James<br />

C (Comput. Phys. Commun. 60 (1990) 329-344), which has been modified to<br />

C give a single random number at each call.<br />

C<br />

C The ’seeds’ ISEED1 and ISEED2 must be initialized in the main program<br />

C and transferred through the named common block /RSEED/.<br />

C<br />

IMPLICIT DOUBLE PRECISION (A-H,O-Z), INTEGER*4 (I-N)<br />

PARAMETER (USCALE=1.0D0/2.0D0**31)<br />

COMMON/RSEED/ISEED1,ISEED2<br />

C<br />

I1=ISEED1/53668<br />

ISEED1=40014*(ISEED1-I1*53668)-I1*12211<br />

IF(ISEED1.LT.0) ISEED1=ISEED1+2147483563<br />

C<br />

I2=ISEED2/52774<br />

ISEED2=40692*(ISEED2-I2*52774)-I2*3791<br />

IF(ISEED2.LT.0) ISEED2=ISEED2+2147483399<br />

C<br />

IZ=ISEED1-ISEED2<br />

IF(IZ.LT.1) IZ=IZ+2147483562<br />

RAND=IZ*USCALE<br />

C<br />

RETURN<br />

END<br />

1.2.2 Inverse transform method<br />

The cumulative distribution function of p(x), eq. (1.6), is a non-decreasing function of x<br />

and, therefore, it has an inverse function P −1 (ξ). The transformation ξ = P(x) defines<br />

a new random variable that takes values in the interval (0,1), see fig. 1.1. Owing to the<br />

correspondence between x and ξ values, the PDF of ξ, p ξ (ξ), and that of x, p(x), are<br />

related by p ξ (ξ) dξ = p(x) dx. Hence,<br />

( ) −1 ( ) −1<br />

dξ<br />

dP(x)<br />

p ξ (ξ) = p(x) = p(x)<br />

= 1, (1.31)<br />

dx<br />

dx<br />

that is, ξ is distributed uniformly in the interval (0,1).<br />

Now it is clear that if ξ is a random number, the variable x defined by x = P −1 (ξ)<br />

is randomly distributed in the interval (x min , x max ) with PDF p(x) (see fig. 1.1). This<br />

provides a practical method of generating random values of x using a generator of<br />

random numbers uniformly distributed in (0,1). The randomness of x is guaranteed by

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

Saved successfully!

Ooh no, something went wrong!