Random Number-modify 2011

Embed Size (px)

DESCRIPTION

RNG

Citation preview

  • RANDOM NUMBERSDr. N. SELVARAJAssociate ProfessorDept. of Mechanical EnggNational Institute of TechnologyWarangal- 506 004

  • Probability, Statistics, and SimulationSimulate random components- Generation ofInterarrivalsService timesBreakdowns/ Repair timesthat are assumed tobehave according to fitted distributions.Simulation ModelDatae.g., InterarrivalsService timesBreakdownsRepair timesDistribution Fitting

    Compute statistics Graphical representation Choose distributionsMass functionsDensity functionsDistribution fcns. Goodness-of-fit tests (statistical inference)Simulation replications

    Warm-upSamples of systemPerformance x1x2xnOutput AnalysisStatistical tests and measures*Statistics & ProbabilityProbabilityStatisticsStatistics processing/analyzing dataProbability Manipulating/utilizing functions

  • OUT LINESRANDOM NUMBER GENERATION

    RANDOM VARIATE GENERATION

  • Random numbers (RN)RN are a necessary basic ingredients in the simulation. Computer languages are having subroutine, objects or function that will generate a RN. Similarly, in simulation languages also generate RN that used to generate event times and other random variables.

  • Random numbers (RN)A random number is any number which is obtained in a manner which has no particular pattern, purpose or reason.

  • Random numbers (RN)A Random number stream is a sequence of random numbers in which each succeeding number is calculated from the previous value derived. The initial number is referred to as the random number seed and determines the starting point of random number generator in its algorithm. RN values generally between 0 and 1 which are used to establish stochastic behavior in simulation models

  • RN GENERATORS(RNG)A RN generator is any mechanism which produces independent random numbers. The term independent implies that the probability of producing any given RN remains the same each time a number is produced.RNGs produce a sequence of RNs, with each new number calculated from the previously computed number. The initial number is referred to as number seed and the sequence of numbers generated from it is called RN stream

  • (RNG)Otherwise, In computer simulation truly RNs cannot be generated because all computer activities are guided by algorithms which are in DETERMINISTICS in nature.However the sequence of RNs called Pseudo RNsPseudo means false or having a deceptive resemblance to

  • (RNG)By definition, a true RN cannot be predicted. Numbers produced by a RNG are calculated, and a calculated number is predictable. Therefore, the numbers created by a RNG are often to called pseudo random number.

  • Random numbers (RN)RNs are widely used in Physics, Computer science, operation research,Numerical Analysis, Management sciences, Social sciences, Statistics, and other areas where chance variables are introduced in the analysis and solution of problems.Majority of the systems are around us in stochastic in nature. So RNs are extensively used in the simulation of such system.

  • RANDOM NUMBER(RN) GENERATIONComputer languages haveSubroutine, object or functions That will generate RNs

  • RANDOM NUMBER(RN) GENERATIONSimulation languages generate RNs . Used to generate event timesOther random Variables (Variate)

  • Physical methodsTables of RNsPack of cardsNumbered tokensSpinning wheelsElectronic counters

  • Physical methodsLimitationsSlowInconvenient or expensive to build and maintain andSequence of numbers is not reproducible for program testing

  • Algebraic MethodsSimplicitySpeed and Reproducibility

  • Algebraic methodsStart with number X0 called seed and produce sequence of the formX1 = f(X0)X2 = f(X1).Xi = f(Xi-1)

  • Algebraic methodsSince the number of digits on a computer is finite. So computer can generate only a finite of distinct numbers.The RNG produced numbers which appears to be random and satisfy most of the tests for randomness are known as Pseudo-random or Quasi random numbers.

  • Statically properties of RNs or A good pseudo random generator must be capable of producing different sequences of numbers which are1.Uniformly distributed between 0 and 1 (non uniform distributions can be generated from uniform distributions)2.Statistically independent (Future random numbers are not influence by past values)3.Reproducible(Repeat the same sequence for testing different versions of a program)

  • Statically properties of RNs4.Non repeating for any desired length ( ie long period. The number of distinct numbers in the sequence must be sufficiently large compared to the number of random numbers needed for an experiment)5.Generated fast and should not use large amounts of computer memory.

  • Maintenance problemMachine break down 1 hr (MTBF)Repair time (MTTR)No randomness in breakdown (MTBF) only deterministic, but MTTR randomness Some machines 1 hr--- 50%Other machines 1.5 hrs---- 50%But MTTR vary from m/c to m/cQueue length depends upon MTTR

  • ObjectivesTo reduce the queue length or the number of m/cs waiting for the serviceTo provide more number of repair facilities or repairmen Labor(servicemen) cost will be moreAny organization to minimize the cost to get profit

  • objectivesIf reduce labor cost . M/cs Queue length will be increase.Cost waiting time of m/cs will increase. (ie unproductive) andSalary paid to workers

  • Two situationsLarge nos of repairmen lead to heavy cost of employee but minimum downtime of cost of m/cs (less queue)Small nos of repairmen lead to reduce cost of employee but large downtime cost of m/cs (un production).Try to reduce one, the other one will invariably increase. So both are conflicting

  • Formulation problemWhat is the no. repair facilities or repairmen we need in order to reduce the total cost?Total cost = sum of waiting time of m/cs x down time cost per hr+ sum of idle time of the repairmen x cost per hr of the repairmen

  • Simulating maintenance systemsOnly one randomness ie repair time. (MTTR)1 hr and 1.5 hrs, the probability of 0.5 and 0.5 Toss a coin Head 1 hr and Tail 1.5 hrAssume that coin is unbiased. So equal probability of .5 and .5 in terms of getting 1 hr and 1.5hr of repair time.

  • Simulating maintenance systemsToss a coin

    Head 1 hr and Tail 1.5 hr

    To sample the repair time

  • Table

  • Simulating maintenance systemsToss a coin ,Head 1 hr and Tail 1.5 hrTo use a computer to simulate this problem.Computer cannot be termed automatically in that event.For example: prob of repair time being equal to 0.4 =1.5hrs, 0.4 = 1.5hrs and 0.2 = 2 hrs . This change makes the use of coin toss is ineffective for sampling the repair time

  • Simulating maintenance systemsWhat mechanism is can we think of in order to sample the repair time.

    There is mechanism of generating a series of numbers between 0 and 1. These numbers are independent of one another and spread uniformly throughout the range 0 and 1

  • Simulating maintenance systemsCase 1: When the number is between 0 and 0.5, it corresponds to 1hr andWhen it is between 0.5 to 1, it corresponds to 1.5hrs of repair timeCase2: If the number is between 0 and 0.4 = 1hr.If the number is between 0.4 and 0.8 = 1.5hrs. If the number is between 0.8 and 1 = 2hrs.

  • Simulating maintenance systemsHow do we get the series of random numbers or stream ?

  • Methods of generating RNsVon Neumanns Mid square method (1940)Von Neumanns Mid product method (1942)Linear congruential method(1951)Multiplicative congruential methodCombined linear congruential method

  • Von Neumanns Mid square methodAdvantagesSimple and easy to implement

    DisadvantagesDid not produce good random sequences andTendency to generate rapidly to zero

  • Von Neumanns Mid square methodXn 4567step 1Xn2 20 8574 89step 2Xn+1 8574 step 3Set Xn = Xn+1 and repeat step 4

    Notes 1.Xn is any K digits long number2.Xn2 is 2K digits long3.Xn+1 is K digit long

  • Von Neumanns Mid square method

    4567 20 8574 8973 5134 7626 3579 5612 8092 41

  • Von Neumanns Mid square method65 4804 6423 0784 1661 465 5621 62 25 3 84 4 7 05 6 2 5

  • Von Neumanns mid product methodAssume four digit numbers A= constant multiplier = 5167X0= Seed number = 3729

  • Von Neuman Mid product methodA.X0 = 5167 x 3729 = 19 2677 43 2677/10,000 = 0.2677AX1 = 7743 x 3729 = 28 8736 478736/10,000 = 0.8736AX2 = 3647 x 3729 = 12 3996 63 3996/ 10,000 = 0.3996And so on Random numbers are 0.2677, 0.8736, 0.3996 etc

  • Linear Congruential methodLehmer (1951), produce sequence of integers X1,X2.between 0 and m-1 by the following recursive relationship.Xi+1 = (aXi + c)mod m , i = 0,1,2Where X0 = initial value (seed)a = multiplier, c = increment and m=modulus When c >1 mixed congruential methodwhen c = 0 multiplicative congruential method

  • Linear Congruential methodX0 = 27, a = 17, c = 43 and m = 100The integer values generated will all be between 0 and 99 because of the value of the modulus.Note: Random integers being generated (0--- 99) rather than RNs. RNs generated by Ri = Xi / m, i=0,1,2.

  • Linear Congruential methodX0 = 27, a = 17, c = 43 and m = 100X1 = (17x27+43) mod 100 = 502 mod 100 = 2, R1 = 2/100 = 0.02X2 = (17x2+43)mod 100 = 77mod 100 = 77, R2 = 77/100 = 0.77X3 =(17x77+43)mod100, =1352mod100=52, R3 =52/100 = 0.52.. RNs are 0.02, 0.77, 0.52 .

  • Linear Congruential methodNote: a=b mod m provided that(b-a) is divisible by m with no reminder. Thus, X1=502mod100, but 502/100 equals 5 with a remainder of 2.so that X1 = 2.OR, (502-2) is evenly divisible by m=100, so X1 = 502 reduces to X1 =2mod100.

  • Frequency distribution of the data needs to be observed by analyst and the intervals of uniform RNs have to be defined corresponding to the actual values ( say repair times). From this, sampling of random variables from the given distribution (called Random variate) is accomplished.

  • TEST FOR RANDOM NUMBERSBasic properties of RNs are Uniformity and IndependenceTo check on whether these properties have been achieved.

  • TEST FOR RANDOM NUMBERSStatistical testsMoment testFrequency testSerial testRuns testsGap testKolmogorov- Smirnov test etc

  • THANK YOU