1 / 16

Christine M. Mitchell Center for Human-Machine Systems Research (chmsr)

ISYE 7210--Simulation of Real-Time Systems Fall 2005 Random Number Generators & Probability Distributions www.chmsr.gatech.edu/ISyE7210 / www.horstmann.com/corejava.html. Christine M. Mitchell Center for Human-Machine Systems Research (chmsr) School of Industrial and Systems Engineering

gtibbs
Download Presentation

Christine M. Mitchell Center for Human-Machine Systems Research (chmsr)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ISYE 7210--Simulation of Real-Time Systems Fall 2005Random Number Generators & Probability Distributions www.chmsr.gatech.edu/ISyE7210/www.horstmann.com/corejava.html Christine M. Mitchell Center for Human-Machine Systems Research (chmsr) School of Industrial and Systems Engineering (chmsr lab) ISyE Main, Room 426, 404 385-0363 (office) ISyE Groseclose, Room 334, 404 894-4321 {cm}@chmsr.gatech.edu

  2. “Lite” Introduction to Discrete-Event Simulation • In discrete-event simulation, time hops from one event to the next • Time is captured in discrete units • Time recorded at • Change of state, e.g., new customer arrives, tn • An event occurse.g., new server joins set of servers, tn + i • In discrete-event simulation, time can be • Deterministic, e.g., time for one customer to depart and another customer to step up to the sever is 1 min. • Stochastic, e.g., time defined by sampling from a probability distribution, such as transaction time is exponentially distributed with mean 5 min. • Example • Entities • Server(s)—such as bank teller(s) • Customers —such as people depositing paycheck

  3. “Lite” Introduction to Discrete-Event Simulation (cont’d) • Example (cont’d) • Discrete events • Customer arrivals at queue (assume one waiting line) • Customer service time (assume one type of transaction) • Time to switch from completed customer (departing) to customer waiting in queue to step up to server • New server arrival • H0: Assume, one server & at least three customers: A at server, B & C in waiting in queue t0 simulation time begins t1 ~ (t1 - t0) A completes transaction (random time) t2 = t1+ 10 s. A departs & B moves to the server (deterministic time) t3 ~ t2 + (t1 - t0) B completes transaction t4 = t3 + 10 s. B departs & C moves to the server t5 customer, D, arrives (random time) t6 ~ t4 + (t1 - t0) C completes transaction t7 secondserver arrives * tn tn + 1 * *

  4. Random Number Generator (RNG) &Pseudo-Random Number Generator (P-RNG) • Random Number Generator (RNG) • An algorithm that generates a sequence of numbers from 0 to MAX_Value (often the largest number a computer can hold) • Sequence is uncorrelated, that is, any number from [0, MAX_VALUE] is equally likely • Numbers are often scaled on the unit interview, [0, 1] • In practice, there is no such thing as a statistically random sequence • For mathematical purposes, e.g., discrete-event simulation timing, use a pseudo-random number generator (P-RNG) • A working definition of random (in the context of a computer-generated sequences) • Deterministic algorithm that produces a sequence of numbers • Sequence is statistically uncorrelated

  5. t3+ .3 t0 t1 t1+ .3 t3 t5 t5 t5 + .3 t6 t7 Pseudo-Random Number Generator (P-RNG) (con’td) • Popular and preferred class of P-RNG is a mixed-congruential type • A mixed-congruential RNG • Sequence of random numbers calculated by adding a random number to the last number obtained • R2 = R1 + Rnew1 • Rn = Rn - 1 + Rnew2 • Allows a modeler to regenerate the same random number stream, given knowledge of the constants and random number seed, xo • Random number, xn+1 , is generated by the nth random number, Xn, by using a recursive formula

  6. Pseudo-Random Number Generator (con’td)A Mixed-Congruential Generator (cont’d) A mixed-congruential P-RNG looks as follows • a, c, and m are positive integers (a < m, c < m) •  Xn+1 is the remainder when (aXn+ c) is dived by m • Xn+1= (aXn + c) (modulo m) • Modulo: m—a large prime integer • Xn has a value in the range 0 to m-1 • Using a computer, the typical choice for m is m = 2*b, where b is the “word size” of the computer, e.g., 16 bit, 32 bit, 64 bit • The multiplier, a, is an integer in the range 1 to m-1

  7. Pseudo-Random Number Generator (con’td)A Mixed-Congruential Generator (cont’d) • A mixed-congruential algorithm looks as follows • f(xn) = xn+1where the generating function f(..) is defined for all x in the range of 1 to m-1 • Sequence of x’s must be initialized by using an initial seed, x0, from the sequence 1, 2, 3, ….., m-1 • Sequence of x’s is conventionally normalized to the unit interval via division by the modulus to produce the sequence, u1, u2, u3, u4, contained in [0, 1] •  un = xn/ m for n = 1, 2, 3, 4, ….

  8. Pseudo-Random Number Generators • Good random number generators are to find!!!! • Always useyour own random number generator • You control the random numbers, not the computer hardware or language (implementation) • Languages, etc., will often start generating random sequences with a different seed (and unknown starting point) for each run • E.g., seconds since 1970 • Even if you can set the seed, may not have control, test this! • Potentially, sad consequences may occur if you need to replicate runs with exactly the same random numbers for each type of event • For example, experiments that include human decision makers

  9. Distribution Class Hierarchy for ISyE 7210

  10. Distribution Class Hierarchy for ISyE 7210

  11. Uniform01: P-RNG & Distribution (cont’d) //Uniform01.java /** Class: Uniform01 Generates uniformly distributed random numbers in the interval [0,1]. I also provides the basis for the pseudo-random number generator for all other probability distribution subclasses. The pseud0-random number generator uses the recursion: IX=16087 * IX mod (2 (31 – 1) ) <br> using only 32 bits including the sign. <p> Code modified from UNIF in Bratley, Fox, and Schrage (1987), <i>A Guide to Simulation (2nd ed)</i>, Springer-Verlag, New York, p. 331. <p> <pre> input: seed...an integer random number from a stream of numbers greater than 0 and less than 2147483647 ~ (2 (31 – 1) ) <p> output: seed = new seed value </pre> //(cont’d)

  12. Uniform01: P-RNG & Distribution (cont’d) //Uniform01.java @author Christine M. Mitchell<BR> * Center for Human-Machine Systems Research<BR> * School of Industrial and Systems Engineering<BR> * Georgia Institute of Technology<BR> * * Last Updated: September 2005 */ public class Uniform01 { private long seed = 0; /** * Sets the internal seed in this class for the * the random number generator */ public Uniform01(long newSeed) //constructor taking one argument, a (long) seed value { seed = newSeed; } /** * Returns the next value from a Uniform distribution on * [0, 1] using recursion above */ //Uniform)1 (cont’d)

  13. Uniform01: P-RNG & Distribution (cont’d) //Uniform01.java public double getNextRandom() { long k1 = 0; double value = 0.0; k1 = seed /127773; seed = 16807 * (seed - k1 * 127773) - k1 *2836; if (seed < 0) seed = seed + 2147483647; //twos-complement if negative value = seed * 4.656612875E-10; //scale to [0, 1] interval return value; } /** * Returns current value of the random number seed */ public long getSeed() { return seed; } //Uniform01 (cont’d)

  14. Uniform01: P-RNG & Distribution (cont’d) //Uniform01.java /** * Resets seed value */ public void setSeed(long newSeed) { seed = newSeed; } /** * Returns string representation of Uniform01 */ public String toString() { return new String("Seed: " + seed + "\t" + "\t" + "RV: " + getNextRandom()); } /** * main tests the class Uniform01 */ //Uniform01 (cont’d)

  15. Uniform01: P-RNG & Distribution (cont’d) //Uniform01.java public static void main (String argv []) { Uniform01 rng1 = new Uniform01(123456789); Uniform01 rng2 = new Uniform01(256712345); System.out.println("Printing from Uniform01 main( )"); System.out.println("Two Uniform [0, 1] distributions"); for (int i = 0; i < 8; i++) { System.out.println(rng1.toString() + "\t" + rng2.toString()); }//end for } //end main }// end class Uniform01 Printing from Uniform01 main( ) Two Uniform [0, 1] distributions Seed: 123456789 RV: 0.2184182969823758 Seed: 256712345 RV: 0.1256054230552947 Seed: 469049721 RV: 0.9563175765089297 Seed: 269735592 RV: 0.05034540176607601 Seed: 2053676357 RV: 0.8295092339327006 Seed: 108115927 RV: 0.15516752709521853 Seed: 1781357515 RV: 0.5616954427668942 Seed: 333219727 RV: 0.9006280269466985 Seed: 1206231778 RV: 0.41530708147596124 Seed: 1934083960 RV: 0.8552496921076923 Seed: 891865166 RV: 0.06611873491603133 Seed: 1836634728 RV: 0.18157601270870943 Seed: 141988902 RV: 0.2575777923820449 Seed: 389931518 RV: 0.7480457563247773 Seed: 553144097 RV: 0.1099567935324706 Seed: 1606416029 RV: 0.4050272141392882

  16. Distributions for ISyE 7210 • Comments on set of probability distributions for 7210 • Each distribution is a Java class • Each distribution generates a pseudo-random stream of random variables from the specified probability distributions • Set of distribution are a good example of the utility of subclassing

More Related