[PDF] Random numbers and Monte Carlo(*) Techniques





Previous PDF Next PDF



Chapter 6 - Random-Number Generation

Linear Congruential Method. Generating Random Numbers. Prof. Dr. Mesut Güneş c without actually generating any numbers. • Empirical tests: applied to actual ...



Random Number Generators

number generator is called a Linear Congruential Generator (LCG) and is defined by a recursion as follows: Zn+1 = (aZn + c) mod m n ≥ 0



UNIT 5:Random number generation And Variation Generation

EXAMPLE 1 Use the linear congruential method to generate a sequence of random numbers with X0 = 27 a= 17





On-line Numerical Recipes in C http://lib-www.lanl.gov/numerical

The linear congruential method has the advantage of being very fast requiring Park and Miller [1] have surveyed a large number of random number generators.



RANDOM NUMBER GENERATION AND ITS BETTER TECHNIQUE

When the increment c=0 it is called multiplicative congruential method. • Linear congruential random number generators are widely used in simulation and.



Chapter 4: (01) Random Number Generation

▫ linear congruential generator (LCG). ➢ a recursive algorithm for The only positive integer that (exactly) divides both m and c is 1 (i.e. c and m have no ...



Chapter 7 Random-Number Generation

▫ The seed for a linear congruential random-number generator: □ Is the integer value X0 that initializes the random-number sequence. □ Any value in the 



Overview of lecture slides 01

Linear congruential algorithm. Simple traditional algorithm: Xn+1 = (aXn + c) mod m Good pseudo-random number generators exist





Chapter 6 - Random-Number Generation

The selection of the values for a c



Random numbers and Monte Carlo(*) Techniques

(pseudo)random numbers generation: example I1 - “Linear congruential method (LCM)”. (Lehemer 1948). In+1 = (a In + c) mod m. Limits of the algorithm:.



993SM - Laboratory of Computational Physics lecture II - part I

17 mar 2021 (pseudo)random numbers generation: example I1 - “Linear congruential method (LCM)”. (Lehemer 1948). In+1 = (a In + c) mod m.



Linear Congruential Generator

Xn+1 = (a*Xn + c)%m – Linear congruential series Code for linear congruential generator ... random number a in (a1a2) distributed as g(a).



993SM - Laboratory of Computational Physics lecture II March 9 2022

9 mar 2022 (pseudo)random numbers generation: example I1 - “Linear congruential method (LCM)”. (Lehemer 1948). In+1 = (a In + c) mod m.



Chapter 7 Random-Number Generation

Techniques for Generating Random. Numbers. ? Linear Congruential Method (LCM). The selection of the values for a c



Chapter 4: (01) Random Number Generation

Linear congruential generator (LCG) A sequence of pseudo-random numbers U(i)



Chapter 7 Random-Number Generation

Techniques for Generating Random. Numbers. ? Linear Congruential Method (LCM). The selection of the values for a c



Systems Simulation Chapter 7: Random-Number Generation

22 apr 2014 The linear congruential method (LCM) produces a sequence of integers X1



Random numbers and Monte Carlo(*) Techniques

(pseudo)random numbers generation: example I1 - “Linear congruential method (LCM)”. (Lehemer 1948). In+1 = (a In + c) mod m. Limits of the algorithm:.



[PDF] Chapter 6 - Random-Number Generation

Combined Linear Congruential Method • Tests for Random Numbers • Real Random Numbers Prof Dr Mesut Güne? ? Ch 6 Random-Number Generation 



[PDF] Chapter 4: (01) Random Number Generation

Pseudo-Random Numbers 8 ? linear congruential generator (LCG) ? a recursive algorithm for producing a sequence of pseudorandom numbers



[PDF] Random Number Generators - Columbia University

The most common and easy to understand and implement random number generator is called a Linear Congruential Generator (LCG) and is defined by a recursion as 



[PDF] 2WB05 Simulation Lecture 5: Random-number generators

Most random-number generators in use today are linear congruential generators They produce a sequence of integers between 0 and m ? 1 according to



[PDF] Chapter 7 Random-Number Generation

Techniques for Generating Random Numbers ? Linear Congruential Method (LCM) The selection of the values for a c m and X0 drastically



[PDF] Linear Congruential Generator - CERN Indico

Linear Congruential Generator ? Goal: Generate Un uniform in the interval [01) ? Generate Xn in [0m) Un = Xn/m ? Xn+1 = (a*Xn + c) m – Linear 



[PDF] RANDOM NUMBER GENERATION AND ITS BETTER TECHNIQUE

Random number generators based on linear recurrences modulo 2 are among the When the increment c=0 it is called multiplicative congruential method



[PDF] Generating random numbers

Linear congruential generator generate more than m/1000 numbers Composite generator X n+1 = a 1 X n + c Shuffling a random number generator



[PDF] Systems Simulation Chapter 7: Random-Number Generation

22 avr 2014 · The linear congruential method (LCM) produces a sequence of integers X1X2 between 0 and m ? 1 by following a recursive relationship Xi+1 



[PDF] Random Number Generator (RNG)

SNU/NUKE/EHK Random Number Generation (cont ) PDF: ?Linear Congruential Generator divisor of c and m is 1) and the multiplier a-1 = 4k where

  • How is the linear congruential method used to generate random numbers?

    A linear congruential generator (LCG) is an algorithm that yields a sequence of pseudo-randomized numbers calculated with a discontinuous piecewise linear equation. The method represents one of the oldest and best-known pseudorandom number generator algorithms.
  • What is the formula for the LCG method?

    The simple form of the LCG algorithm is as follows: X n+1 = (a X n +b) mod m , n? 0 ; A constant in the above algorithm is called a multiplier, the constant b is called an increment, and the constant m is called modulus.
  • What is the formula for linear congruential generator?

    An LCG is defined by the equation Ln ? (a ? Ln-1 + c) mod m, where the values of m (the modulus, a positive integer), a (the multiplier, a positive integer less than m) and c (the increment, either 0 or a positive integer less than m) are chosen by the designer of the LCG.
  • Full-Period Theorem (Hull and Dobell, 1966) In general, cycle length determined by parameters m, a, and c: The LCG Zi = (aZi-1 + c) (mod m) has full period (m) if and only all three of the following hold: 1. c and m are relatively prime (i.e., the only positive integer that divides both c and m is 1).

Random numbers

and Monte Carlo

Techniques

M. Peressi - UniTS - Laurea Magistrale in Physics

Laboratory of Computational Physics - Unit II

(*) any procedure making use of random numbers

Random numbers: use

in numerical analysis (to calculate integrals) to simulate and model complex or intrinsically random phenomena to generate data encryption keys

Monte Carlo Methods: to calculate integrals

Hit or Miss Method: !"w much is ! ?

A 1 C B y x 0 1

Algorithm: •!Generate uniform, random x and y between 0 and 1 •!Calculate the distance from the origin: d=(x 2 +y 2 1/2 •!If d # 1, ! hit hit + 1 •!Repeat for ! tot trials tot hit 4

OABC Square of Area

CA Curve Under Area x 4

Random numbers:

Characteristics and

Generation

Random numbers

... but with a well defined statistical properties, e.g.:

True random numbers generation

Pseudo random numbers generation

with a computer "pseudo" because they are necessarily generated with deterministic procedures (the computer is a deterministic apparatus!)

A sequence of computer generated random numbers

is not truly random, since each number is completely determined from the previous one.

But it may "appear" to be random.

(pseudo)Random numbers generation the sequence may "appear" to be random I n [ Attention: in a code, write: x n =float(I n )/M !!!]

INTEGER

(pseudo)Random numbers generation many different algorithms...

Two among the simplest (and oldest) algorithms:

- von Neumann - Linear Congruential Method (pseudo)random numbers generation: example 1 - "Middle square" algorithm (Von Neumann, 1946)

To generate a 10-digit integer sequence:

- take a first one - square it - take the middle 10 digits of the result

Also this sequence may "appear" to be random.

Limits of the algorithm:

depending on the initial choice, you can be trapped into short loops: loop (pseudo)random numbers generation: example I1 - "Linear congruential method (LCM)" (Lehemer, 1948) I n+1 = (a I n + c) mod m

Limits of the algorithm: "A mod m" is the

remainder of the division of

A by m

QUESTIONS:

- in which interval are the pseudorandom numbers generated? - Can we obtain all the numbers in such interval? - Is the sequence periodic? - Which is the period? - Which is the maximum period? LCM: I n+1 = (a I n + c) mod m More subtle limits, even of some smart algorithms... x i , p(x i )(x i , x i+1

65539=2

16 +3; initial seed I 0 : odd number

Why? Hint: show that: x

k+2 =6x k+1 -9x k Problems also with other smart algorithms ...(now 3rd edition, see: http://www.nr.com/)

Possible improvements

- uniformity (look at the histogram, but also check the moments of the distribution, i.e., , for k=1, 2, ...) - correlation - other more sophisticated tests (in particular for cryptographically secure use!)

Tests the "quality" of a

random sequence

Many other (pseudo)random

numbers generators - "Mersenne twister" ( Matsumoto and Nishimura , 1997 ) The commonly used variant, MT19937, produces a sequence of 32-bit integers with the following desirable properties:

1.It has a very long period of 2

19937

1 (which is necessary but not sufficient to guarantee of

good quality in a random number generator)

2. It passes numerous tests for statistical randomness

true vs pseudo random number generators non deterministic periodicityperiodicaperiodic

Technicalities to create our own

(pseudo)random number generator mod ???

Intrinsic procedures in FORTRAN

(see link to Chapman book in my Web page) EXPANDED DESCRIPTION OF FORTRAN 90 / 95 INTRINSIC PROCEDURES

Intrinsic procedures in FORTRAN

(see link to Chapman book in my Web page) Fortran 90/95 Intrinsic Procedure Descriptions, a supplement to Introduction to Fortran 90/95, by Stephen J. Chapman 5

LEN(STRING)LEN(str)IntegerB.7

LEN_TRIM(STRING)IntegerB.7

LGE(STRING_A, STRING_B)LogicalB.7

LGT(STRING_A, STRING_B)LogicalB.7

LLE(STRING_A, STRING_B)LogicalB.7

LLT(STRING_A, STRING_B)LogicalB.7

LOG(X)Argument typeB.3

ALOG(r)Real

CLOG(c)Complex

DLOG(d)Double Prec.

LOG10(X)Argument typeB.3

ALOG10(r)Real

DLOG10(d)Double Prec.

LOGICAL(L, KIND)LogicalB.3

MATMUL(MATRIX_A, MATRIX_B)Argument typeB.3

MAX(A1,A2,A3, ...)Argument typeB.3

AMAX0(i1,i2, ...)Real1

AMAX1(r1,r2, ...)Real1

DMAX1(d1,d2,...)Double Prec.1

MAX0(i1,i2,...)Integer1

MAX1(r1,r2,...)Integer1

MAXEXPONENT(X)IntegerB.4

MAXLOC(ARRAY, DIM, MASK)IntegerB.86

MAXVAL(ARRAY, DIM, MASK)Argument typeB.8

MERGE(TSOURCE,FSOURCE,MASK)Argument typeB.8

MIN(A1,A2,A3, ...)Argument typeB.3

AMIN0(i1,i2, ...)Real1

AMIN1(r1,r2, ...)Real1

DMIN1(d1,d2,...)Double Prec.1

MIN0(i1,i2,...)Integer1

MIN1(r1,r2,...)Integer1

MINEXPONENT(X)IntegerB.4

MINLOC(ARRAY, DIM, MASK)IntegerB.86

MINVAL(ARRAY, DIM, MASK)Argument typeB.8

MOD(A,P)Argument typeB.3

AMOD(r1,r2)Real

MOD(i,j)Integer

DMOD(d1,d2)Double Prec.

MODULO(A,P)Argument typeB.3

MVBITS(FROM, FROMPOS, LEN, TO,

TOPOS)

SubroutineB.6

NEAREST(X,S)RealB.3

NINT(A, KIND)IntegerB.3

IDNINT(i)Integer

NINT(x)Integer

NOT(I)Argument typeB.6

NULL(MOLD)PointerB.85

PACK(ARRAY, MASK, VECTOR)Argument typeB.8

PRECISION(X)IntegerB.4

PRESENT(A)LogicalB.9

Intrinsic procedures in FORTRAN

(see link to Chapman book in my Web page) Fortran 90/95 Intrinsic Procedure Descriptions, a supplement to Introduction to Fortran 90/95, by Stephen J. Chapman 11 • Arguments may be Real or Integer; all must be of the same type

MIN(A1,A2,A3,...)

• Elemental function of same kind as its arguments • Returns the minimum value of A1, A2, etc. • Arguments may be Real or Integer; all must be of the same type

MOD(A1,P)

• Elemental function of same kind as its arguments • Returns the value MOD(A,P) = A - P*INT(A/P) if P ! 0. Results are processor dependent if P = 0. • Arguments may be Real or Integer; they must be of the same type • Examples:

FunctionResult

MOD(5,3)2

MOD(-5,3)-2

MOD(5,-3)2

MOD(-5,-3)-2

MODULO(A1,P)

• Elemental function of same kind as its arguments • Returns the modulo of A wi th respect to P if P ! 0. Result s are processor dependent if P = 0. • Arguments may be Real or Integer; they must be of the same type • If P > 0, then the function determines the positive difference between A and then next lowest multiple of P. If P < 0, then the function determines the negative difference between A and then next highest multiple of P. • Results agree with the MOD function for two positive or two negative arguments; results disagree for arguments of mixed signs. • Examples:

FunctionResultExplanation

MODULO(5,3)25 is 2 up from 3

MODULO(-5,3)1-5 is 1 up from -6

MODULO(5,-3)-15 is 1 down from 6

MODULO(-5,-3)-2-5 is 2 down from -3

NEAREST(X,S)

• Real elemental function • Returns the nearest m achine-repres entable number different from X in the direction of S. The returned value will be of the same kind as X. • X and S are Real, and S ! 0

NINT(A,KIND)

• Integer elemental function mod or modulo give the same result if acting on positive integers

Modulus operator in C++

the language provides a built-in mechanism, the modulus operator ('%').

Example:

01 #include

02 using namespace std;

03

04 int main()

05 {

06 !!!!int M = 8;

07 !!!!int a = 5;

08 !!!!int c = 3;

09 !!!!int X = 1;

10 !!!!int i;

11 !!!!for(i=0; i<8; i++)

12 !!!!{

13 !!!!!!!!X = (a * X + c) % M;

14 !!!!!!!!cout << X << " ";

15

16 !!!!return 0;

17 }

Intrinsic pseudorandom numbers generators

We could create our own random number generator

using "mod" intrinsic function, but it is much better to use directly the (smart) intrinsic procedures provided by the compilers to generate random numbers, in general: real, with uniform distribution in [0;1[

Es. :

in Fortran90: subroutine random_number( ) in fortran77: function drand48( ) in Pascal: function Random in C: function rand ...

Intrinsic pseudorandom numbers generator

in FORTRAN Fortran 90/95 Intrinsic Procedure Descriptions, a supplement to Introduction to Fortran 90/95, by Stephen J. Chapman 6

PRODUCT(ARRAY, DIM, MASK)Argument typeB.8

RADIX(X)IntegerB.4

RANDOM_NUMBER(HARVEST)SubroutineB.3

RANDOM_SEED(SIZE, PUT, GET)SubroutineB.3

RANGE(X)IntegerB.4

REAL(A, KIND)RealB.3

FLOAT(i)Real1

SNGL(d)Real1

REPEAT(STRING, NCOPIES)CharacterB.7

RESHAPE(SOURCE,SHAPE,PAD,

ORDER)

Argument typeB.8

RRSPACING(X)Argument typeB.4

SCALE(X, I)Argument typeB.4

SCAN(STRING, SET, BACK)IntegerB.7

SELECTED_INT_KIND(R)IntegerB.4

SELECTED_REAL_KIND(P,R)IntegerB.43

SET_EXPONENT(X, I)Argument typeB.4

SHAPE(SOURCE)IntegerB.8

SIGN(A,B)Argument typeB.3

DSIGN(d1,d2)Double Prec.

ISIGN(i1,i2)Integer

SIGN(r1,r2)Real

SIN(X)Argument typeB.3

CSIN(c)Complex

quotesdbs_dbs17.pdfusesText_23
[PDF] linear dilaton cft

[PDF] linear equations

[PDF] linear equations examples

[PDF] linear optimization pdf

[PDF] linear phase fir filter

[PDF] linear programming

[PDF] linear programming unbounded

[PDF] linear programming examples

[PDF] linear programming graphical method with 3 variables pdf

[PDF] linear programming is a

[PDF] linear programming model examples

[PDF] linear programming pdf

[PDF] linear programming problems

[PDF] linear programming simplex method

[PDF] linear programming simplex method minimization problems with solutions pdf