Random Number Generators - a brief assessment of those available

Size: px
Start display at page:

Download "Random Number Generators - a brief assessment of those available"

Transcription

1 Random Number Generators - a brief assessment of those available Anna Mills March 30, Introduction Nothing in nature is random...a thing appears random only through the incompleteness of our knowledge. Spinoza In everyday life, we are used to random phenomena, in the drawing of lottery numbers, or in rolling a dice. Spinoza would claim that such things are not truly random. The lottery numbers to emerge, for instance, could be predicted, if one knew the precise starting conditions of the urn and lottery balls and the precise actions of the lottery master in drawing the balls. Here lies the important issue in generating random numbers on a computer. We in fact seek to produce numbers that appear to be random within acceptable parameters. To emphasize this distinction we use the term, pseudorandom. Kahaner, Moler and Nash [1] define five areas in which one should assess a given random number generator, as follows. 1. Quality - Suitable statistical tests should be satisfied. There should be a sufficiently long period before repetition occurs. 2. Efficiency - The generator should be quick to run. Minimal storage must be required. 3. Repeatability - The method should be seedable, to allow an experiment to be reproduced. 1

2 4. Portability - If the method is implemented on a different system it should produce the same results. 5. Simplicity - The generator should be straightforward both to implement and to use. 2 The middle square generator - an unsatisfactory method One of the earliest attempts at computerized random number generation was a middle square generator. An example of such an algorithm is given below. 1. Seed the generator with some integer, z 0 (1, 9999] 2. Then z n+1 is given by 4 middle digits of (z n ) 2, for n as large as required. 3. The n th value, U n (0, 1) is then given by zn An example progression is given below. z 0 = 1010 (z 0 ) 2 = z 1 = 2010 (z 1 ) 2 = z 2 = 4010 (z 2 ) 2 = z 3 = 0801 (z 3 ) 2 = Methods of generation such as this were first suggested by Jon Von Neumann in about 1946 and were very popular in the early days of computer programming. Such methods are flawed, however, since they can easily settle into patterns of very short period. I continued the series above, using MATLAB, and found that it settles into a pattern of period 67. Carrying out a χ 2 test showed the generator not to conform to uniformity over the unit interval. 3 The Fibonacci generator - another flawed method The set of Fibonacci generators, popular in the 1950s, are based on a method of generation similar to that of the Fibonacci sequence. In its simplest form, we 2

3 have an initial seed vector containing two values between 0 and 1, perhaps taken from a table, and the relation x k = x k 1 x k 2 (1) I implemented this in MATLAB, and found the results highly unsatisfactory, settling down to a sequence of period length 6, a section of which is shown in Figure Figure 1: A plot of the values 10:60 of a simple Fibonacci generator Better results are given by sampling from earlier within the distribution to compute the next value, x k. If, for instance, we have, x k = x k 97 x k 33, then we say we have a Fibonacci generator with lags 97 and 33. These particular values were in fact implemented in the random number generators of some supercomputers in the 1960s. However, Fibonacci generators have since been found to fail simple tests for randomness, as in the following example. Take three consecutive values of a sequence, U k 1, U k, U k+1. In ordering these three values, simple combinatorics tells us that there are six possible relative orders, U k < U k 1 < U k+1,..., U k > U k 1 > U k+1. Now, if we examine one particular ordering, say the first on our list, U k < U k 1 < U k+1 (2) 3

4 then we should expect this to occur in approximately one sixth of samples from the distribution. However, this sequence never occurs in the Fibonacci sequence, as shown below. Without loss of generality, we can examine the simplest Fibonacci generator in (1). Then we have { Uk U k 1 if U k > U k 1, U k+1 = U k U k if U k < U k 1. Then, U k < U k 1 U k+1 < U k U k+1 < U k < U k 1, so we can never have the above case in (2). The generalization to systems of lag greater than 1 is a straightforward exercise. This analytical dismissal of the Fibonacci generator is an example of a case where a generator can pass many statistical tests carried out by computation, as do many Fibonacci generators of high lag, but can fail a simple pen and paper test. This is a warning that one must plan carefully before creating a random number generator. 4 The Lehmer generator - a better approach The Lehmer generator is also known as the prime modulus multiplicative linear congruential generator. It is the most widely implemented of the class of linear congruential generators. There are three parameters: modulus m - a large integer which must be prime, multiplier a - an integer in the range (2, 3,..., m 1), additive constant c - an integer, often equal to 0. There must also be an initial value, z 1. The consequent pseudorandom values are then generated by the formula: z k+1 = (az k + c)mod m. This generates a sequence drawn at random ranging from 1 to m 1, without replacement. A combination of parameters which leads to a sequence of numbers with period m 1 is described as having full period. 4

5 As with the middle square generator, the values of z k, are generally normalized to lie on the unit interval. So the final random values are given by U k = z k m for k = 1, 2,.... The success of such a generator is depent on the choice of parameters. With a choice of m = 11, for instance, the multiplier a = 8 yields a sequence of full period, whereas the multiplier a = 9 has a sequence of period length 5, as shown in the sequences below... a = , 8, 9, 6, 4, 10, 3, 2, 5, 7, 1... a = , 9, 4, 3, 5, Park and Miller [8] give suitable choices to be m = = and a = = 7 5. This yields a full period generator. A histogram showing the behaviour of this generator is shown in Figure 2. The MATLAB code used to generate this histogram is given in Section Figure 2: A histogram showing values of the Lehmer generator with parameters a = 7 5, m = The histogram shows that each of the 25 divisions contains approximately 2000 numbers, as we would expect from a uniform distribution. A χ 2 test gives 5

6 us no evidence to reject the hypothesis that the sample is from a uniform distribution. Until the release of MATLAB version 5, MATLAB used a random number generator with the parameters as suggested by Park and Miller. From version 5, however, MATLAB has used a subtract with borrow generator, as described in Section 5. This is much faster and has longer period length than the previous generator. 4.1 RANDU - an embarrassment for IBM The IBM corporation used a Lehmer generator for its SYSTEM/360 product, RANDU. This generator used U 0 odd, U n+1 = (65539 U n )(mod 2 31 ). The first thing to notice about these parameters is that the modulus, m, is not prime. In implementing a linear congruential generator, programmers were eager to produce a fast generator. The code ran more quickly with a modulus that was a power of two, so the value 2 31 was chosen. The generator fails most tests for randomness that examine consecutive triples due to the following relation. 9 U n 6 U n+1 + U n+2 = 0(mod 2 31 ) This is very simple to check using the fragment of code below. The output, test is a null vector so clearly RANDU is disqualified as a random generator. % RANDU produces a vector of supposedly pseudo-random numbers % based on IBM s generator, then tests for relations in % 3-tuples. clear all;format compact; m = 2^31; a = 65539; t = zeros(1,3); z(1) = 1; 6

7 for k = 1:100; for i = 1:3 z(3*(k - 1) + i + 1) = mod(a * z(3*(k - 1) + i), m); t(k,:) = [z(3 * (k - 1) + 1),z(3 * (k - 1) + 2),z(3 * (k - 1) + 3)]; test = mod(9 * t(:, 1) - 6 * t(:, 2) + t(:, 3), m) Such a relation could cause very serious errors in any experiment using random numbers. For instance, it is easy to imagine how using random numbers thus flawed in a 3-dimensional application such as using a Monte Carlo method for estimation of integration in 3 dimensions could cause catastrophically inaccurate results. 5 Subtract with borrow generators - an improved and faster method In 1995, Moler [7] suggested that the period of just over two billion for the Lehmer generator, although acceptable previously, was becoming inadequate due to the development of much faster processors. An alternative is the subtract with borrow generator, as proposed by Marsaglia in 1968 [4]. The scheme does not, as with many previous methods, generate large integers and then normalize to the unit interval, but rather generates floating point numbers. Previous generators had required only one number as initial seed. Marsaglia proposed a generator that required a 35 element vector as initial seed. A vector, U, is required, containing 32 random, uniformly distributed numbers between 0 and 1. These could, perhaps, be generated by sampling from the output of a Lehmer generator shown to give an acceptable uniform output, such as discussed in Section 4. They are treated as forming a cyclic sequence, for instance, if i = 32, then z i+1 is equivalent to z 1. The cycles are easy to calculate, since treating the sequence as a cycle merely corresponds to dealing only with the last five bits of the indices. 7

8 The iteration for generating the numbers is given by U 0 i = U i+p + U i+q b (3) where b is a value inherited from the previous step using the rule zi 0 0 b = 0, z i = zi 0, zi 0 < 0 b = 2 53, z i = zi With the values p = 8 and q = 22, this is known as the RCARRY generator, having period Implemented with values p = 20 and q = 5, Marsaglia has shown the period of the generator to be approximately In the random number implementation in MATLAB (after version 5), there is a further stage to the generation, using the 35 th element of the initial seed and an XOR operation further to improve the quality of the sequence that is generated. Cleve Moler [7], Chairman of the Math Works who produce MATLAB states that the period of the generator is then approximately The Wolfram Research program, Mathematica, also uses a subtract with borrow algorithm for the generation of random numbers 1. 6 A note on implementation issues Although the Lehmer generator with carefully chosen parameters is shown to give satisfactory results, it is very easy to produce code that gives terrible results. To illustrate this, I have written an implementation in Fortran 90 which on first glance perhaps seems a faithful reproduction of the Lehmer generator with the parameters of Section PROGRAM random_int 02 IMPLICIT NONE INTEGER :: seed = 1 05 INTEGER :: a = See The Mathematica Book, section A.9.4 for details 8

9 06 INTEGER :: m = INTEGER, DIMENSION(10000) :: output 08 INTEGER :: i= DO i = 1, seed = modulo(a * seed, m) 12 output(i) = seed 13 END DO 14 PRINT *, seed 15 END PROGRAM random_int OUTPUT: > Park and Miller [8] give an implementation test that the above parameters should yield z as This is clearly not what our Fortran 90 implementation produces, so we must examine what goes wrong when the above code runs. In the execution of the above program, at line 11 at stage k, we could potentially have seed = = m 1. At stage k + 1, we would then have the calculation a (m 1), which with the default integer range of Fortran 90, will cause overflow. This is because the default range for integer values in Fortran 90 is (2 31 1) to (2 31 1). In fact we will encounter overflow at the stage following any value greater than , making all following values inaccurate and potentially not conforming to a uniform distribution. In this case, we can easily eliminate the overflow difficulty by declaring our parameters as reals rather than integers, but the importance of ensuring a suitable implementation of a random generator is clear from this example. Other suitable precautions must clearly be taken when one is faced with a maximum integer of less than , as discussed by Park and Miller [8]. Clearly, the creation of a successful random number generator goes far beyond the invention of a pleasing algorithm. It is important to consider all the aspects of 9

10 quality from Section 5. The fastest generators may take advantage of the characteristics of a specific machine and so not be portable, and a code that is portable may well be slow to run. Perhaps to look for the best random number generator in the abstract is not a useful task, but rather we should choose a particular generator with characteristics and strengths suitable for the application. 7 Accompanying MATLAB codes 7.1 Code to run and analyze a Lehmer generator % LEHMER produces a vector of pseudo-random numbers % based on the Lehmer generator. m = 2^31-1; a = 7^5; z(1) = 1; r = 0; k = 1; while r == 0 ; z(k + 1) = mod(a * z(k), m); if z(k + 1) == z(1); r = 1; k = k + 1; function f = binstest2(a); % BINSTEST sorts the entries of vector, A, then distributes them into 25 % bins [0,0.04],...,[0.96,1.0] and returns the result of a chi-squared % test relating to the expected values for each bin, n/25, where n is the % length of A. A = sort(a); n = length(a); if (A(1) < 0 A(n) > 1) 10

11 disp ( INPUT ERROR: data not in range [0,1] ) return b = zeros(1,25); r = 1; for k = 1:n adv = 0; while adv == 0 if ((r - 1) * 0.04 < A(k) & A(k) <= r * 0.04) b(r) = b(r) + 1; adv = 1; else r = r + 1; % advance to the next bin bar(b); %A chi squared test is carried out chi2 = 0; for k = 1:25 chi2 = chi2 + ( (b(k) - n/25)^2 )/ (n/25); if chi2 < f = 0.05; elseif chi2 < f = 0.01; elseif chi2 < f = 0.001; else f = 0; 11

12 References [1] D. Kahaner: Numerical Methods and Software, Prentice Hall Series in Computational Mathematics (1977) [2] D. E. Knuth: The Art of Computer Programming, Addison-Wesley Vol. 2 Seminumerical Algorithms (1997) [3] M. Donald MacLaren and George Marsaglia: Uniform Random Number Generators, Journal of the Association for Computing Machinery/Volume 12/Number 1 (January, 1965), pp [4] George Marsaglia: Random Numbers Fall Mainly in the Planes, Proceedings of the National Academy of Sciences/Volume 61 (1968), pp [5] George Marsaglia and T. A. Bray: One Line Random Number Generators and Their Use in Combinations, Communications of the ACM/Volume 11/Number 11 (November, 1968), pp [6] George Marsaglia and Arif Azman: Toward a Universal Random Number Generator, Letters in Statistics and Probability/Letters 8 (January, 1990), pp [7] Cleve Moler: Random Thoughts, MATLAB News and Notes (Fall, 1995) [8] Stephen K. Park, Keith. W. Miller: Random Number Generators: Good Ones are Hard to Find, Communications of the ACM/Volume 31/Number 10 (October, 1988), pp

2008 Winton. Review of Statistical Terminology

2008 Winton. Review of Statistical Terminology 1 Review of Statistical Terminology 2 Formal Terminology An experiment is a process whose outcome is not known with certainty The experiment s sample space S is the set of all possible outcomes. A random

More information

Review of Statistical Terminology

Review of Statistical Terminology Review of Statistical Terminology An experiment is a process whose outcome is not known with certainty. The experiment s sample space S is the set of all possible outcomes. A random variable is a function

More information

Random numbers and generators

Random numbers and generators Chapter 2 Random numbers and generators Random numbers can be generated experimentally, like throwing dice or from radioactive decay measurements. In numerical calculations one needs, however, huge set

More information

Generating Uniform Random Numbers

Generating Uniform Random Numbers 1 / 41 Generating Uniform Random Numbers Christos Alexopoulos and Dave Goldsman Georgia Institute of Technology, Atlanta, GA, USA 10/13/16 2 / 41 Outline 1 Introduction 2 Some Lousy Generators We Won t

More information

Algorithms and Networking for Computer Games

Algorithms and Networking for Computer Games Algorithms and Networking for Computer Games Chapter 2: Random Numbers http://www.wiley.com/go/smed What are random numbers good for (according to D.E. Knuth) simulation sampling numerical analysis computer

More information

Generating Uniform Random Numbers

Generating Uniform Random Numbers 1 / 43 Generating Uniform Random Numbers Christos Alexopoulos and Dave Goldsman Georgia Institute of Technology, Atlanta, GA, USA March 1, 2016 2 / 43 Outline 1 Introduction 2 Some Generators We Won t

More information

Uniform Random Number Generators

Uniform Random Number Generators JHU 553.633/433: Monte Carlo Methods J. C. Spall 25 September 2017 CHAPTER 2 RANDOM NUMBER GENERATION Motivation and criteria for generators Linear generators (e.g., linear congruential generators) Multiple

More information

B. Maddah ENMG 622 Simulation 11/11/08

B. Maddah ENMG 622 Simulation 11/11/08 B. Maddah ENMG 622 Simulation 11/11/08 Random-Number Generators (Chapter 7, Law) Overview All stochastic simulations need to generate IID uniformly distributed on (0,1), U(0,1), random numbers. 1 f X (

More information

Lehmer Random Number Generators: Introduction

Lehmer Random Number Generators: Introduction Lehmer Random Number Generators: Introduction Revised version of the slides based on the book Discrete-Event Simulation: a first course LL Leemis & SK Park Section(s) 21, 22 c 2006 Pearson Ed, Inc 0-13-142917-5

More information

A Repetition Test for Pseudo-Random Number Generators

A Repetition Test for Pseudo-Random Number Generators Monte Carlo Methods and Appl., Vol. 12, No. 5-6, pp. 385 393 (2006) c VSP 2006 A Repetition Test for Pseudo-Random Number Generators Manuel Gil, Gaston H. Gonnet, Wesley P. Petersen SAM, Mathematik, ETHZ,

More information

Generating Uniform Random Numbers

Generating Uniform Random Numbers 1 / 44 Generating Uniform Random Numbers Christos Alexopoulos and Dave Goldsman Georgia Institute of Technology, Atlanta, GA, USA 10/29/17 2 / 44 Outline 1 Introduction 2 Some Lousy Generators We Won t

More information

Monte Carlo Techniques

Monte Carlo Techniques Physics 75.502 Part III: Monte Carlo Methods 40 Monte Carlo Techniques Monte Carlo refers to any procedure that makes use of random numbers. Monte Carlo methods are used in: Simulation of natural phenomena

More information

Uniform Random Binary Floating Point Number Generation

Uniform Random Binary Floating Point Number Generation Uniform Random Binary Floating Point Number Generation Prof. Dr. Thomas Morgenstern, Phone: ++49.3943-659-337, Fax: ++49.3943-659-399, tmorgenstern@hs-harz.de, Hochschule Harz, Friedrichstr. 57-59, 38855

More information

Topics in Computer Mathematics

Topics in Computer Mathematics Random Number Generation (Uniform random numbers) Introduction We frequently need some way to generate numbers that are random (by some criteria), especially in computer science. Simulations of natural

More information

CPSC 531: Random Numbers. Jonathan Hudson Department of Computer Science University of Calgary

CPSC 531: Random Numbers. Jonathan Hudson Department of Computer Science University of Calgary CPSC 531: Random Numbers Jonathan Hudson Department of Computer Science University of Calgary http://www.ucalgary.ca/~hudsonj/531f17 Introduction In simulations, we generate random values for variables

More information

Tae-Soo Kim and Young-Kyun Yang

Tae-Soo Kim and Young-Kyun Yang Kangweon-Kyungki Math. Jour. 14 (2006), No. 1, pp. 85 93 ON THE INITIAL SEED OF THE RANDOM NUMBER GENERATORS Tae-Soo Kim and Young-Kyun Yang Abstract. A good arithmetic random number generator should possess

More information

How does the computer generate observations from various distributions specified after input analysis?

How does the computer generate observations from various distributions specified after input analysis? 1 How does the computer generate observations from various distributions specified after input analysis? There are two main components to the generation of observations from probability distributions.

More information

Lecture 20. Randomness and Monte Carlo. J. Chaudhry. Department of Mathematics and Statistics University of New Mexico

Lecture 20. Randomness and Monte Carlo. J. Chaudhry. Department of Mathematics and Statistics University of New Mexico Lecture 20 Randomness and Monte Carlo J. Chaudhry Department of Mathematics and Statistics University of New Mexico J. Chaudhry (UNM) CS 357 1 / 40 What we ll do: Random number generators Monte-Carlo integration

More information

Contents. 1 Probability review Introduction Random variables and distributions Convergence of random variables...

Contents. 1 Probability review Introduction Random variables and distributions Convergence of random variables... Contents Probability review. Introduction..............................2 Random variables and distributions................ 3.3 Convergence of random variables................. 6 2 Monte Carlo methods

More information

Section 2.1: Lehmer Random Number Generators: Introduction

Section 2.1: Lehmer Random Number Generators: Introduction Section 21: Lehmer Random Number Generators: Introduction Discrete-Event Simulation: A First Course c 2006 Pearson Ed, Inc 0-13-142917-5 Discrete-Event Simulation: A First Course Section 21: Lehmer Random

More information

A TEST OF RANDOMNESS BASED ON THE DISTANCE BETWEEN CONSECUTIVE RANDOM NUMBER PAIRS. Matthew J. Duggan John H. Drew Lawrence M.

A TEST OF RANDOMNESS BASED ON THE DISTANCE BETWEEN CONSECUTIVE RANDOM NUMBER PAIRS. Matthew J. Duggan John H. Drew Lawrence M. Proceedings of the 2005 Winter Simulation Conference M. E. Kuhl, N. M. Steiger, F. B. Armstrong, and J. A. Joines, eds. A TEST OF RANDOMNESS BASED ON THE DISTANCE BETWEEN CONSECUTIVE RANDOM NUMBER PAIRS

More information

Random Number Generation. Stephen Booth David Henty

Random Number Generation. Stephen Booth David Henty Random Number Generation Stephen Booth David Henty Introduction Random numbers are frequently used in many types of computer simulation Frequently as part of a sampling process: Generate a representative

More information

Chapter 4: Monte Carlo Methods. Paisan Nakmahachalasint

Chapter 4: Monte Carlo Methods. Paisan Nakmahachalasint Chapter 4: Monte Carlo Methods Paisan Nakmahachalasint Introduction Monte Carlo Methods are a class of computational algorithms that rely on repeated random sampling to compute their results. Monte Carlo

More information

How does the computer generate observations from various distributions specified after input analysis?

How does the computer generate observations from various distributions specified after input analysis? 1 How does the computer generate observations from various distributions specified after input analysis? There are two main components to the generation of observations from probability distributions.

More information

Uniform and Exponential Random Floating Point Number Generation

Uniform and Exponential Random Floating Point Number Generation Uniform and Exponential Random Floating Point Number Generation Thomas Morgenstern Hochschule Harz, Friedrichstr. 57-59, D-38855 Wernigerode tmorgenstern@hs-harz.de Summary. Pseudo random number generators

More information

( ) ( ) Monte Carlo Methods Interested in. E f X = f x d x. Examples:

( ) ( ) Monte Carlo Methods Interested in. E f X = f x d x. Examples: Monte Carlo Methods Interested in Examples: µ E f X = f x d x Type I error rate of a hypothesis test Mean width of a confidence interval procedure Evaluating a likelihood Finding posterior mean and variance

More information

Uniform random numbers generators

Uniform random numbers generators Uniform random numbers generators Lecturer: Dmitri A. Moltchanov E-mail: moltchan@cs.tut.fi http://www.cs.tut.fi/kurssit/tlt-2707/ OUTLINE: The need for random numbers; Basic steps in generation; Uniformly

More information

Topic Contents. Factoring Methods. Unit 3: Factoring Methods. Finding the square root of a number

Topic Contents. Factoring Methods. Unit 3: Factoring Methods. Finding the square root of a number Topic Contents Factoring Methods Unit 3 The smallest divisor of an integer The GCD of two numbers Generating prime numbers Computing prime factors of an integer Generating pseudo random numbers Raising

More information

Generating Random Variables

Generating Random Variables Generating Random Variables These slides are created by Dr. Yih Huang of George Mason University. Students registered in Dr. Huang's courses at GMU can make a single machine-readable copy and print a single

More information

4.5 Applications of Congruences

4.5 Applications of Congruences 4.5 Applications of Congruences 287 66. Find all solutions of the congruence x 2 16 (mod 105). [Hint: Find the solutions of this congruence modulo 3, modulo 5, and modulo 7, and then use the Chinese remainder

More information

Cryptographic Pseudo-random Numbers in Simulation

Cryptographic Pseudo-random Numbers in Simulation Cryptographic Pseudo-random Numbers in Simulation Nick Maclaren University of Cambridge Computer Laboratory Pembroke Street, Cambridge CB2 3QG. A fruitful source of confusion on the Internet is that both

More information

Sum-discrepancy test on pseudorandom number generators

Sum-discrepancy test on pseudorandom number generators Sum-discrepancy test on pseudorandom number generators Makoto Matsumoto a,, Takuji Nishimura b a Faculty of Science, Hiroshima University, Hiroshima 739-8526, JAPAN b Faculty of Science, Yamagata University,

More information

Random processes and probability distributions. Phys 420/580 Lecture 20

Random processes and probability distributions. Phys 420/580 Lecture 20 Random processes and probability distributions Phys 420/580 Lecture 20 Random processes Many physical processes are random in character: e.g., nuclear decay (Poisson distributed event count) P (k, τ) =

More information

Simulation. Where real stuff starts

Simulation. Where real stuff starts 1 Simulation Where real stuff starts ToC 1. What is a simulation? 2. Accuracy of output 3. Random Number Generators 4. How to sample 5. Monte Carlo 6. Bootstrap 2 1. What is a simulation? 3 What is a simulation?

More information

Pseudo-Random Numbers Generators. Anne GILLE-GENEST. March 1, Premia Introduction Definitions Good generators...

Pseudo-Random Numbers Generators. Anne GILLE-GENEST. March 1, Premia Introduction Definitions Good generators... 14 pages 1 Pseudo-Random Numbers Generators Anne GILLE-GENEST March 1, 2012 Contents Premia 14 1 Introduction 2 1.1 Definitions............................. 2 1.2 Good generators..........................

More information

Random Number Generation. CS1538: Introduction to simulations

Random Number Generation. CS1538: Introduction to simulations Random Number Generation CS1538: Introduction to simulations Random Numbers Stochastic simulations require random data True random data cannot come from an algorithm We must obtain it from some process

More information

Random numbers and random number generators

Random numbers and random number generators Random numbers and random number generators It was a very popular deterministic philosophy some 300 years ago that if we know initial conditions and solve Eqs. of motion then the future is predictable.

More information

THE SOLOVAY STRASSEN TEST

THE SOLOVAY STRASSEN TEST THE SOLOVAY STRASSEN TEST KEITH CONRAD 1. Introduction The Jacobi symbol satisfies many formulas that the Legendre symbol does, such as these: for a, b Z and odd m, n Z +, (1) a b mod n ( a n ) = ( b n

More information

IE 303 Discrete-Event Simulation L E C T U R E 6 : R A N D O M N U M B E R G E N E R A T I O N

IE 303 Discrete-Event Simulation L E C T U R E 6 : R A N D O M N U M B E R G E N E R A T I O N IE 303 Discrete-Event Simulation L E C T U R E 6 : R A N D O M N U M B E R G E N E R A T I O N Review of the Last Lecture Continuous Distributions Uniform distributions Exponential distributions and memoryless

More information

Fast and Reliable Random Number Generators for Scientific Computing (extended abstract)

Fast and Reliable Random Number Generators for Scientific Computing (extended abstract) Fast and Reliable Random Number Generators for Scientific Computing (extended abstract) Richard P. Brent 1 Oxford University Computing Laboratory, Wolfson Building, Parks Road, Oxford OX1 3QD, UK random@rpbrent.co.uk

More information

Hands-on Generating Random

Hands-on Generating Random CVIP Laboratory Hands-on Generating Random Variables Shireen Elhabian Aly Farag October 2007 The heart of Monte Carlo simulation for statistical inference. Generate synthetic data to test our algorithms,

More information

Physical Tests for Random Numbers. in Simulations. P.O. Box 9 (Siltavuorenpenger 20 C) FIN{00014 University of Helsinki. Finland

Physical Tests for Random Numbers. in Simulations. P.O. Box 9 (Siltavuorenpenger 20 C) FIN{00014 University of Helsinki. Finland Physical Tests for Random Numbers in Simulations I. Vattulainen, 1;2 T. Ala{Nissila, 1;2 and K. Kankaala 2;3 1 Research Institute for Theoretical Physics P.O. Box 9 (Siltavuorenpenger 20 C) FIN{00014 University

More information

A NEW RANDOM NUMBER GENERATOR USING FIBONACCI SERIES

A NEW RANDOM NUMBER GENERATOR USING FIBONACCI SERIES International J. of Math. Sci. & Engg. Appls. (IJMSEA) ISSN 0973-9424, Vol. 11 No. I (April, 2017), pp. 185-193 A NEW RANDOM NUMBER GENERATOR USING FIBONACCI SERIES KOTTA NAGALAKSHMI RACHANA 1 AND SOUBHIK

More information

Statistics, Data Analysis, and Simulation SS 2013

Statistics, Data Analysis, and Simulation SS 2013 Mainz, May 2, 2013 Statistics, Data Analysis, and Simulation SS 2013 08.128.730 Statistik, Datenanalyse und Simulation Dr. Michael O. Distler 2. Random Numbers 2.1 Why random numbers:

More information

Uniform Random Number Generators for Supercomputers

Uniform Random Number Generators for Supercomputers Uniform Random Number Generators for Supercomputers Richard P. Brent 1 Computer Sciences Laboratory Australian National University Abstract We consider the requirements for uniform pseudo-random number

More information

Slides 3: Random Numbers

Slides 3: Random Numbers Slides 3: Random Numbers We previously considered a few examples of simulating real processes. In order to mimic real randomness of events such as arrival times we considered the use of random numbers

More information

1.1 Linear Congruential Method D. H. Lehmer [15] introduced in 1948 the idea of generating a random number sequence using the following formula: X n+1

1.1 Linear Congruential Method D. H. Lehmer [15] introduced in 1948 the idea of generating a random number sequence using the following formula: X n+1 Testing Pseudo-Random Number Generators Abstract Julian Ortiz C. and Clayton V. Deutsch (jmo1@ualberta.ca - cdeutsch@civil.ualberta.ca) Department of Civil& Environmental Engineering, University of Alberta

More information

Systems Simulation Chapter 7: Random-Number Generation

Systems Simulation Chapter 7: Random-Number Generation Systems Simulation Chapter 7: Random-Number Generation Fatih Cavdur fatihcavdur@uludag.edu.tr April 22, 2014 Introduction Introduction Random Numbers (RNs) are a necessary basic ingredient in the simulation

More information

Introduction to Divide and Conquer

Introduction to Divide and Conquer Introduction to Divide and Conquer Sorting with O(n log n) comparisons and integer multiplication faster than O(n 2 ) Periklis A. Papakonstantinou York University Consider a problem that admits a straightforward

More information

Are the Digits in a Mersenne Prime Random? A Probability Model

Are the Digits in a Mersenne Prime Random? A Probability Model Are the in a Are the in a Prime Random? October 11, 2016 1 / 21 Outline Are the in a 1 2 3 4 5 2 / 21 Source Are the in a This talk is my expansion of the blog post: Strings of in, gottwurfelt.com, Jan

More information

B.N.Bandodkar College of Science, Thane. Random-Number Generation. Mrs M.J.Gholba

B.N.Bandodkar College of Science, Thane. Random-Number Generation. Mrs M.J.Gholba B.N.Bandodkar College of Science, Thane Random-Number Generation Mrs M.J.Gholba Properties of Random Numbers A sequence of random numbers, R, R,., must have two important statistical properties, uniformity

More information

Fast Fraction-Integer Method for Computing Multiplicative Inverse

Fast Fraction-Integer Method for Computing Multiplicative Inverse Fast Fraction-Integer Method for Computing Multiplicative Inverse Hani M AL-Matari 1 and Sattar J Aboud 2 and Nidal F Shilbayeh 1 1 Middle East University for Graduate Studies, Faculty of IT, Jordan-Amman

More information

1 Divide and Conquer (September 3)

1 Divide and Conquer (September 3) The control of a large force is the same principle as the control of a few men: it is merely a question of dividing up their numbers. Sun Zi, The Art of War (c. 400 C.E.), translated by Lionel Giles (1910)

More information

arxiv:hep-lat/ v2 10 Aug 1993

arxiv:hep-lat/ v2 10 Aug 1993 1 A Comparative Study of Some Pseudorandom Number Generators I. Vattulainen 1, K. Kankaala 1,2, J. Saarinen 1, and T. Ala-Nissila 1,3 arxiv:hep-lat/9304008 v2 10 Aug 1993 1 Department of Electrical Engineering

More information

2 P. L'Ecuyer and R. Simard otherwise perform well in the spectral test, fail this independence test in a decisive way. LCGs with multipliers that hav

2 P. L'Ecuyer and R. Simard otherwise perform well in the spectral test, fail this independence test in a decisive way. LCGs with multipliers that hav Beware of Linear Congruential Generators with Multipliers of the form a = 2 q 2 r Pierre L'Ecuyer and Richard Simard Linear congruential random number generators with Mersenne prime modulus and multipliers

More information

Some long-period random number generators using shifts and xors

Some long-period random number generators using shifts and xors ANZIAM J. 48 (CTAC2006) pp.c188 C202, 2007 C188 Some long-period random number generators using shifts and xors Richard P. Brent 1 (Received 6 July 2006; revised 2 July 2007) Abstract Marsaglia recently

More information

Theoretical Cryptography, Lectures 18-20

Theoretical Cryptography, Lectures 18-20 Theoretical Cryptography, Lectures 18-20 Instructor: Manuel Blum Scribes: Ryan Williams and Yinmeng Zhang March 29, 2006 1 Content of the Lectures These lectures will cover how someone can prove in zero-knowledge

More information

Workshop on Heterogeneous Computing, 16-20, July No Monte Carlo is safe Monte Carlo - more so parallel Monte Carlo

Workshop on Heterogeneous Computing, 16-20, July No Monte Carlo is safe Monte Carlo - more so parallel Monte Carlo Workshop on Heterogeneous Computing, 16-20, July 2012 No Monte Carlo is safe Monte Carlo - more so parallel Monte Carlo K. P. N. Murthy School of Physics, University of Hyderabad July 19, 2012 K P N Murthy

More information

UNIT 5:Random number generation And Variation Generation

UNIT 5:Random number generation And Variation Generation UNIT 5:Random number generation And Variation Generation RANDOM-NUMBER GENERATION Random numbers are a necessary basic ingredient in the simulation of almost all discrete systems. Most computer languages

More information

Class 12. Random Numbers

Class 12. Random Numbers Class 12. Random Numbers NRiC 7. Frequently needed to generate initial conditions. Often used to solve problems statistically. How can a computer generate a random number? It can t! Generators are pseudo-random.

More information

2008 Winton. Statistical Testing of RNGs

2008 Winton. Statistical Testing of RNGs 1 Statistical Testing of RNGs Criteria for Randomness For a sequence of numbers to be considered a sequence of randomly acquired numbers, it must have two basic statistical properties: Uniformly distributed

More information

Random number generation

Random number generation CE 391F April 4, 2013 ANNOUNCEMENTS Homework 3 due today Homework 4 coming... Announcements Webinar announcement Femke van Wageningen-Kessels from TU Delft will be giving a webinar titled Traffic Flow

More information

Uniform Random Number Generators for Vector and Parallel Computers

Uniform Random Number Generators for Vector and Parallel Computers Uniform Random Number Generators for Vector and Parallel Computers Richard P. Brent Computer Sciences Laboratory Australian National University Canberra, ACT 0200 rpb@cslab.anu.edu.au Report TR-CS-92-02

More information

14 Random Variables and Simulation

14 Random Variables and Simulation 14 Random Variables and Simulation In this lecture note we consider the relationship between random variables and simulation models. Random variables play two important roles in simulation models. We assume

More information

Simulation. Where real stuff starts

Simulation. Where real stuff starts Simulation Where real stuff starts March 2019 1 ToC 1. What is a simulation? 2. Accuracy of output 3. Random Number Generators 4. How to sample 5. Monte Carlo 6. Bootstrap 2 1. What is a simulation? 3

More information

Lecture 2 : CS6205 Advanced Modeling and Simulation

Lecture 2 : CS6205 Advanced Modeling and Simulation Lecture 2 : CS6205 Advanced Modeling and Simulation Lee Hwee Kuan 21 Aug. 2013 For the purpose of learning stochastic simulations for the first time. We shall only consider probabilities on finite discrete

More information

Computer Applications for Engineers ET 601

Computer Applications for Engineers ET 601 Computer Applications for Engineers ET 601 Asst. Prof. Dr. Prapun Suksompong prapun@siit.tu.ac.th Random Variables (Con t) 1 Office Hours: (BKD 3601-7) Wednesday 9:30-11:30 Wednesday 16:00-17:00 Thursday

More information

Some long-period random number generators using shifts and xors

Some long-period random number generators using shifts and xors Some long-period random number generators using shifts and xors Richard. P. Brent 2 July 2007 Abstract Marsaglia recently introduced a class of xorshift random number generators (RNGs) with periods 2 n

More information

Adam Blank Spring 2017 CSE 311. Foundations of Computing I. * All slides are a combined effort between previous instructors of the course

Adam Blank Spring 2017 CSE 311. Foundations of Computing I. * All slides are a combined effort between previous instructors of the course Adam Blank Spring 2017 CSE 311 Foundations of Computing I * All slides are a combined effort between previous instructors of the course HW 3 De-Brief HW 3 De-Brief PROOFS! HW 3 De-Brief Proofs This is

More information

Random Number Generators: Metrics and Tests for Uniformity and Randomness

Random Number Generators: Metrics and Tests for Uniformity and Randomness Random Number Generators: Metrics and Tests for Uniformity and Randomness E. A. Yfantis and J. B. Pedersen Image Processing, Computer Vision and Machine Intelligence Lab School of Computer Science College

More information

Department of Electrical- and Information Technology. ETS061 Lecture 3, Verification, Validation and Input

Department of Electrical- and Information Technology. ETS061 Lecture 3, Verification, Validation and Input ETS061 Lecture 3, Verification, Validation and Input Verification and Validation Real system Validation Model Verification Measurements Verification Break model down into smaller bits and test each bit

More information

CSCE 564, Fall 2001 Notes 6 Page 1 13 Random Numbers The great metaphysical truth in the generation of random numbers is this: If you want a function

CSCE 564, Fall 2001 Notes 6 Page 1 13 Random Numbers The great metaphysical truth in the generation of random numbers is this: If you want a function CSCE 564, Fall 2001 Notes 6 Page 1 13 Random Numbers The great metaphysical truth in the generation of random numbers is this: If you want a function that is reasonably random in behavior, then take any

More information

Some long-period random number generators using shifts and xors

Some long-period random number generators using shifts and xors Introduction Some long-period random number generators using shifts and xors Richard P. Brent MSI & RSISE, ANU Canberra, ACT 0200 CTAC06@rpbrent.com Marsaglia recently proposed a class of uniform random

More information

Finally, a theory of random number generation

Finally, a theory of random number generation Finally, a theory of random number generation F. James, CERN, Geneva Abstract For a variety of reasons, Monte Carlo methods have become of increasing importance among mathematical methods for solving all

More information

Stochastic Simulation of Communication Networks

Stochastic Simulation of Communication Networks Stochastic Simulation of Communication Networks Part 2 Amanpreet Singh (aps) Dr.-Ing Umar Toseef (umr) (@comnets.uni-bremen.de) Prof. Dr. C. Görg www.comnets.uni-bremen.de VSIM 2-1 Table of Contents 1

More information

Contents Functions Remarks and examples Methods and formulas Acknowledgments References Also see

Contents Functions Remarks and examples Methods and formulas Acknowledgments References Also see Title stata.com Random-number functions Contents Functions Remarks and examples Methods and formulas Acknowledgments References Also see Contents rbeta(a,b) rbinomial(n,p) rchi2(df) rexponential(b) rgamma(a,b)

More information

Motivation. Dictionaries. Direct Addressing. CSE 680 Prof. Roger Crawfis

Motivation. Dictionaries. Direct Addressing. CSE 680 Prof. Roger Crawfis Motivation Introduction to Algorithms Hash Tables CSE 680 Prof. Roger Crawfis Arrays provide an indirect way to access a set. Many times we need an association between two sets, or a set of keys and associated

More information

Universal Juggling Cycles

Universal Juggling Cycles Universal Juggling Cycles Fan Chung y Ron Graham z Abstract During the past several decades, it has become popular among jugglers (and juggling mathematicians) to represent certain periodic juggling patterns

More information

11 Division Mod n, Linear Integer Equations, Random Numbers, The Fundamental Theorem of Arithmetic

11 Division Mod n, Linear Integer Equations, Random Numbers, The Fundamental Theorem of Arithmetic 11 Division Mod n, Linear Integer Equations, Random Numbers, The Fundamental Theorem of Arithmetic Bezout s Lemma Let's look at the values of 4x + 6y when x and y are integers. If x is -6 and y is 4 we

More information

2 Elementary algorithms for one-dimensional integrals

2 Elementary algorithms for one-dimensional integrals PY 502, Computational Physics, Fall 2017 Numerical Integration and Monte Carlo Integration Anders W. Sandvik, Department of Physics, Boston University 1 Introduction A common numerical task in computational

More information

Random Number Generators

Random Number Generators 1/18 Random Number Generators Professor Karl Sigman Columbia University Department of IEOR New York City USA 2/18 Introduction Your computer generates" numbers U 1, U 2, U 3,... that are considered independent

More information

Chapter 9 Mathematics of Cryptography Part III: Primes and Related Congruence Equations

Chapter 9 Mathematics of Cryptography Part III: Primes and Related Congruence Equations Chapter 9 Mathematics of Cryptography Part III: Primes and Related Congruence Equations Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9.1 Chapter 9 Objectives

More information

COMS 6100 Class Notes

COMS 6100 Class Notes COMS 6100 Class Notes Daniel Solus September 20, 2016 1 General Remarks The Lecture notes submitted by the class have been very good. Integer division seemed to be a common oversight when working the Fortran

More information

Sources of randomness

Sources of randomness Random Number Generator Chapter 7 In simulations, we generate random values for variables with a specified distribution Ex., model service times using the exponential distribution Generation of random

More information

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers ALGEBRA CHRISTIAN REMLING 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers by Z = {..., 2, 1, 0, 1,...}. Given a, b Z, we write a b if b = ac for some

More information

Primality Testing SURFACE. Syracuse University. Per Brinch Hansen Syracuse University, School of Computer and Information Science,

Primality Testing SURFACE. Syracuse University. Per Brinch Hansen Syracuse University, School of Computer and Information Science, Syracuse University SURFACE Electrical Engineering and Computer Science Technical Reports College of Engineering and Computer Science 6-1992 Primality Testing Per Brinch Hansen Syracuse University, School

More information

Computer Applications for Engineers ET 601

Computer Applications for Engineers ET 601 Computer Applications for Engineers ET 601 Asst. Prof. Dr. Prapun Suksompong prapun@siit.tu.ac.th Random Variables (Con t) 1 Office Hours: (BKD 3601-7) Wednesday 9:30-11:30 Wednesday 16:00-17:00 Thursday

More information

Finding Succinct. Ordered Minimal Perfect. Hash Functions. Steven S. Seiden 3 Daniel S. Hirschberg 3. September 22, Abstract

Finding Succinct. Ordered Minimal Perfect. Hash Functions. Steven S. Seiden 3 Daniel S. Hirschberg 3. September 22, Abstract Finding Succinct Ordered Minimal Perfect Hash Functions Steven S. Seiden 3 Daniel S. Hirschberg 3 September 22, 1994 Abstract An ordered minimal perfect hash table is one in which no collisions occur among

More information

1: Please compute the Jacobi symbol ( 99

1: Please compute the Jacobi symbol ( 99 SCORE/xx: Math 470 Communications Cryptography NAME: PRACTICE FINAL Please show your work write only in pen. Notes are forbidden. Calculators, all other electronic devices, are forbidden. Brains are encouraged,

More information

Exercises for Discrete Maths

Exercises for Discrete Maths Exercises for Discrete Maths Discrete Maths Rosella Gennari http://www.inf.unibz.it/~gennari gennari@inf.unibz.it Computer Science Free University of Bozen-Bolzano Disclaimer. The course exercises are

More information

2. Accelerated Computations

2. Accelerated Computations 2. Accelerated Computations 2.1. Bent Function Enumeration by a Circular Pipeline Implemented on an FPGA Stuart W. Schneider Jon T. Butler 2.1.1. Background A naive approach to encoding a plaintext message

More information

Drawing Skeletal (Zig-Zag) Structures. The quick and easy way to draw organic molecules

Drawing Skeletal (Zig-Zag) Structures. The quick and easy way to draw organic molecules Drawing Skeletal (Zig-Zag) Structures The quick and easy way to draw organic molecules Information Overload vs Quick and Easy In a line-bond structure you see EVERYTING (except for lone pairs, actually).

More information

Numerical methods for lattice field theory

Numerical methods for lattice field theory Numerical methods for lattice field theory Mike Peardon Trinity College Dublin August 9, 2007 Mike Peardon (Trinity College Dublin) Numerical methods for lattice field theory August 9, 2007 1 / 37 Numerical

More information

METHODS FOR GENERATION OF RANDOM NUMBERS IN PARALLEL STOCHASTIC ALGORITHMS FOR GLOBAL OPTIMIZATION

METHODS FOR GENERATION OF RANDOM NUMBERS IN PARALLEL STOCHASTIC ALGORITHMS FOR GLOBAL OPTIMIZATION METHODS FOR GENERATION OF RANDOM NUMBERS IN PARALLEL STOCHASTIC ALGORITHMS FOR GLOBAL OPTIMIZATION Algirdas Lančinskas, Julius Žilinskas Institute of Mathematics and Informatics 1. Introduction Generation

More information

S.A. Teukolsky, Computers in Physics, Vol. 6, No. 5,

S.A. Teukolsky, Computers in Physics, Vol. 6, No. 5, Physics 75.502 Part III: Monte Carlo Methods 139 Part III: Monte Carlo Methods Topics: Introduction Random Number generators Special distributions General Techniques Multidimensional simulation References:

More information

Chi Square Analysis M&M Statistics. Name Period Date

Chi Square Analysis M&M Statistics. Name Period Date Chi Square Analysis M&M Statistics Name Period Date Have you ever wondered why the package of M&Ms you just bought never seems to have enough of your favorite color? Or, why is it that you always seem

More information

Conceptual Explanations: Simultaneous Equations Distance, rate, and time

Conceptual Explanations: Simultaneous Equations Distance, rate, and time Conceptual Explanations: Simultaneous Equations Distance, rate, and time If you travel 30 miles per hour for 4 hours, how far do you go? A little common sense will tell you that the answer is 120 miles.

More information

New Minimal Weight Representations for Left-to-Right Window Methods

New Minimal Weight Representations for Left-to-Right Window Methods New Minimal Weight Representations for Left-to-Right Window Methods James A. Muir 1 and Douglas R. Stinson 2 1 Department of Combinatorics and Optimization 2 School of Computer Science University of Waterloo

More information

Q 1 Find the square root of 729. 6. Squares and Square Roots Q 2 Fill in the blank using the given pattern. 7 2 = 49 67 2 = 4489 667 2 = 444889 6667 2 = Q 3 Without adding find the sum of 1 + 3 + 5 + 7

More information

Mathematics for Game Theory

Mathematics for Game Theory Mathematics for Game Theory Christoph Schottmüller August 9, 6. Continuity of real functions You might recall that a real function is continuous if you can draw it without lifting the pen. That gives a

More information