Algorithms and Networking for Computer Games

Similar documents
B. Maddah ENMG 622 Simulation 11/11/08

Topics in Computer Mathematics

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

Random number generation

2008 Winton. Review of Statistical Terminology

Review of Statistical Terminology

Generating Uniform Random Numbers

Generating Uniform Random Numbers

Statistics, Data Analysis, and Simulation SS 2013

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

Lehmer Random Number Generators: Introduction

Generating Uniform Random Numbers

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

Uniform random numbers generators

Monte Carlo Techniques

Generating Random Variables

4.5 Applications of Congruences

Random Number Generators - a brief assessment of those available

Slides 3: Random Numbers

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

Uniform Random Number Generators

Random Number Generation. CS1538: Introduction to simulations

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

Section 2.1: Lehmer Random Number Generators: Introduction

cse 311: foundations of computing Fall 2015 Lecture 12: Primes, GCD, applications

cse 311: foundations of computing Fall 2015 Lecture 11: Modular arithmetic and applications

cse 311: foundations of computing Spring 2015 Lecture 12: Primes, GCD, applications

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

Number Theory: Applications. Number Theory Applications. Hash Functions II. Hash Functions III. Pseudorandom Numbers

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

Random number generators

S6880 #6. Random Number Generation #2: Testing RNGs

ENEE 459-C Computer Security. Message authentication (continue from previous lecture)

Lecture 5: Random numbers and Monte Carlo (Numerical Recipes, Chapter 7) Motivations for generating random numbers

CSE 20 DISCRETE MATH. Winter

Random Number Generators: Metrics and Tests for Uniformity and Randomness

NORTHWESTERN UNIVERSITY Tuesday, Oct 6th, 2015 ANSWERS FALL 2015 NU PUTNAM SELECTION TEST

MODULAR ARITHMETIC I

So far we discussed random number generators that need to have the maximum length period.

Chapter 7 Random Numbers

Uniform Random Binary Floating Point Number Generation

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

Integer factorization, part 1: the Q sieve. part 2: detecting smoothness. D. J. Bernstein

A Repetition Test for Pseudo-Random Number Generators

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

Hashing, Hash Functions. Lecture 7

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

Mean Intensity. Same units as I ν : J/m 2 /s/hz/sr (ergs/cm 2 /s/hz/sr) Function of position (and time), but not direction

Lecture Notes. Advanced Discrete Structures COT S

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

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

Notes. Number Theory: Applications. Notes. Number Theory: Applications. Notes. Hash Functions I

A NEW RANDOM NUMBER GENERATOR USING FIBONACCI SERIES

Random Number Generation. Stephen Booth David Henty

Lecture 5: Two-point Sampling

Algorithms lecture notes 1. Hashing, and Universal Hash functions

Lecture 4: Two-point Sampling, Coupon Collector s problem

Insert Sorted List Insert as the Last element (the First element?) Delete Chaining. 2 Slide courtesy of Dr. Sang-Eon Park

Arithmetic, Algebra, Number Theory

CSE 20 DISCRETE MATH. Fall

IE 581 Introduction to Stochastic Simulation. One page of notes, front and back. Closed book. 50 minutes. Score

CHAPTER 3. Congruences. Congruence: definitions and properties

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

CHAPTER 1 REAL NUMBERS KEY POINTS

Introduction CSE 541

Finite Fields. SOLUTIONS Network Coding - Prof. Frank H.P. Fitzek

Chapter 4: Monte Carlo Methods. Paisan Nakmahachalasint

Simulation. Version 1.1 c 2010, 2009, 2001 José Fernando Oliveira Maria Antónia Carravilla FEUP

An A Priori Determination of Serial Correlation in Computer Generated Random Numbers

MATH Dr. Halimah Alshehri Dr. Halimah Alshehri

Symbol-table problem. Hashing. Direct-access table. Hash functions. CS Spring Symbol table T holding n records: record.

Tae-Soo Kim and Young-Kyun Yang

1 Probability Review. CS 124 Section #8 Hashing, Skip Lists 3/20/17. Expectation (weighted average): the expectation of a random quantity X is:

Cosc 412: Cryptography and complexity Lecture 7 (22/8/2018) Knapsacks and attacks

{ 0! = 1 n! = n(n 1)!, n 1. n! =

Lecture Notes. Advanced Discrete Structures COT S

CS1800 Discrete Structures Fall 2017 October, CS1800 Discrete Structures Midterm Version A

EECS150 - Digital Design Lecture 21 - Design Blocks

CSE 311 Lecture 13: Primes and GCD. Emina Torlak and Kevin Zatloukal

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

1 Maintaining a Dictionary

Data Structures and Algorithm. Xiaoqing Zheng

BmMT 2017 Individual Round Solutions November 19, 2017

MAT 243 Test 2 SOLUTIONS, FORM A

Systems Simulation Chapter 7: Random-Number Generation

Finally, a theory of random number generation

ECEN 5022 Cryptography

Random number generators and random processes. Statistics and probability intro. Peg board example. Peg board example. Notes. Eugeniy E.

Chapter 4 Mathematics of Cryptography

Lecture: Analysis of Algorithms (CS )

CSE 502 Class 11 Part 2

Class 12. Random Numbers

Fault Tolerance & Reliability CDA Chapter 2 Cyclic Polynomial Codes

Algorithms (II) Yu Yu. Shanghai Jiaotong University

2030 LECTURES. R. Craigen. Inclusion/Exclusion and Relations

UNIT 5:Random number generation And Variation Generation

SEVENTH EDITION and EXPANDED SEVENTH EDITION

π π π points:= { seq([n*cos(pi/4*n), N*sin(Pi/4*N)], N=0..120) }:

CPSC 467: Cryptography and Computer Security

(x 1 +x 2 )(x 1 x 2 )+(x 2 +x 3 )(x 2 x 3 )+(x 3 +x 1 )(x 3 x 1 ).

Transcription:

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 programming decision-making aesthetics recreation Chapter 2 Slide 2

Random numbers? there is no such thing as a random number is 42 a random number? definition: a sequence of statistically independent random numbers with a uniform distribution numbers are obtained by chance they have nothing to do with the other numbers in the sequence uniform distribution: each possible number is equally probable Chapter 2 Slide 3

Methods random selection drawing balls out of a well-stirred urn tables of random digits decimals from π generating data white noise generators cosmic background radiation computer programs? Chapter 2 Slide 4

Generating random numbers with arithmetic operations von Neumann (ca. 1946): middle square method take the square of previous number and extract the middle digits example: four-digit numbers r i = 8269 r i + 1 = 3763 (r( 2 i = 683763 376361) 61) r i + 2 = 1601 (r( i + 1 2 = 141601 160169) 69) r i + 3 = 5632 (r( i + 2 2 = 2563201) Chapter 2 Slide 5

Truly random numbers? each number is completely determined by its predecessor! sequence is not random but appears to be pseudo-random numbers all random generators based arithmetic operation have their own in-built characteristic regularities hence, testing and analysis is required Chapter 2 Slide 6

Middle square (revisited) another example: r i = 6100 r i + 1 = 2100 (r( 2 i = 372100 210000) 00) r i + 2 = 4100 (r( i + 1 2 = 441004 410000) 00) r i + 3 = 8100 (r( i + 2 2 = 168100 810000) r i + 4 = 6100 = r i (r i + 3 2 = 656100 610000) how to counteract? Chapter 2 Slide 7

Words of the wise random numbers should not be generated with a method chosen at random D. E. Knuth Any one who considers arithmetical methods of producing random digits is, of course, in a state of sin. J. von Neumann Chapter 2 Slide 8

Words of the more (or less) wise We guarantee that each number is random individually, but we don t guarantee that more than one of them is random. anonymous computer centre s programming consultant (quoted in Numerical Recipes in C) C Chapter 2 Slide 9

Other concerns speed of the algorithm ease of implementation parallelization techniques portable implementations Chapter 2 Slide 10

Linear congruential method D. H. Lehmer (1949) choose four integers modulus: m (0 < m) multiplier: a (0 a < m) increment: c (0 c < m) starting value (or seed): X 0 (0 X 0 < m) obtain a sequence X n by setting + 1 = (ax( n + c) ) mod m (n 0) X n + 1 Chapter 2 Slide 11

Linear congruential method (cont d) let b = a 1 generalization: X n + k = (a( k X n + (a( k 1) c/b) ) mod m (k 0, n 0) random floating point numbers U n [0, 1): U n = X n / m Chapter 2 Slide 12

Random integers from a given Monte Carlo methods interval approximate solution accuracy can be improved at the cost of running time Las Vegas methods exact solution termination is not guaranteed Sherwood methods exact solution, termination guaranteed reduce the difference between good and bad inputs Chapter 2 Slide 13

Choice of modulus m sequence of random numbers is finite period (repeating cycle) period has at most m elements modulus should be large recommendation: m is a prime reducing modulo: m is a power of 2 m = 2 i : x mod m = x п (2 i 1) Chapter 2 Slide 14

Choice of multiplier a period of maximum length a = c = 1: X n + 1 = (X( n + 1) mod m hardly random:, 0, 1, 2,, m 1, 0, 1, 2, results from Theorem 2.1.1 if m is a product of distinct primes, only a = 1 produces full period if m is divisible by a high power of some prime, there is latitude when choosing a rules of thumb 0.01m < a < 0.99m no simple, regular bit patterns in the binary representation Chapter 2 Slide 15

Choice of increment c no common factor with m c = 1 c = a if c = 0, addition operation can be eliminated faster processing period length decreases Chapter 2 Slide 16

Choice of starting value X 0 determines from where in the sequence the numbers are taken to guarantee randomness, initialization from a varying source built-in in clock of the computer last value from the previous run using the same value allows to repeat the sequence Chapter 2 Slide 17

Tests for randomness 1(2) Frequency test Serial test Gap test Poker test Coupon collector s test Chapter 2 Slide 18

Tests for randomness 2(2) Permutation test Run test Collision test Birthday spacings test Spectral test Chapter 2 Slide 19

Spectral test good generators will pass it bad generators are likely to fail it idea: let the length of the period be m take t consecutive numbers construct a set of t-dimensional points: { (X( n, X n + 1, 1,, X n + t 1 ) 0 n < m } when t increases the periodic accuracy decreases a truly random sequence would retain the accuracy Chapter 2 Slide 20

Random shuffling generate random permutation, where all permutations have a uniform random distribution shuffling inverse sorting (!) ordered set S = s 1,, s n to be shuffled naïve solution enumerate all possible n!! permutations generate a random integer [1, n!] and select the corresponding permutation practical only when n is small Chapter 2 Slide 21

Random sampling without replacement guarantees that the distribution of permutations is uniform every element has a probability 1/n to become selected in the first position subsequent position are filled with the remaining n 1 elements because selections are independent, the probability of any generated ordered set is 1/n 1/(n 1) 1/(n 2) 1/1 = 1/n! there are exactly n!! possible permutations generated ordered sets have a uniform distribution Chapter 2 Slide 22

Premo: Standard order Chapter 2 Slide 23

Premo: After a riffle shuffle and card insertion Chapter 2 Slide 24

Premo: The inserted card Chapter 2 Slide 25

Random numbers in games terrain generation events character creation decision-making game world compression synchronized simulation Chapter 2 Slide 26

Game world compression used in Elite (1984) finite and discrete galaxy enumerate the positions set the seed value generate a random value for each position if smaller than a given density, create a star otherwise, space is void each star is associated with a randomly generated number, which used as a seed when creating the star system details (name, composition, planets) can be hierarchically extended Chapter 2 Slide 27

Terrain generation 1(2) simple random limited random particle deposition Chapter 2 Slide 28

Terrain generation 2(2) fault line circle hill midpoint displacement Chapter 2 Slide 29