Simulation is a way to model random events, such that simulated outcomes closely match real-world outcomes. By observing simulated outcomes, researchers gain insight on the real world. A simulation generally refers to a computerized version of the model which is run over time to study the implications of the defined interactions. Simulations are generally iterative in there development. One develops a model, simulates it, learns from the simulation, revises the model, and continues the iterations until an adequate level of understanding is developed. Some situations do not lend themselves to precise mathematical treatment. Others may be difficult, time-consuming, or expensive to analyze. In these situations, simulation may approximate real-world results; yet, require less time, effort, and/or money than other approaches.
4.1 STEPS REQUIRED FOR SIMULATION
A simulation is useful only if it closely mirrors real-world outcomes. The steps required to produce a useful simulation are presented below.
1. Describe the possible outcomes.
2. Link each outcome to one or more random numbers.
3. Choose a source of random numbers.
4. Choose a random number.
5. Based on the random number, note the "simulated" outcome.
6. Repeat steps 4 and 5 multiple times; preferably, until the outcomes show a stable pattern.
7. Analyze the simulated outcomes and report results.
4.1 RANDOM NUMBERS
The problem of generating uniform variates by computer has been solved long ago. After all, every computer: system offers one or more function(s) to do so. Many software products, like compilers, spreadsheets, statistical or numerical packages, etc. also offer their own. These functions supposedly return numbers that could be used, for all practical purposes, as if they were the values taken by independent random variables, with a uniform distribution between 0 and 1.
Despite recent advances, blatantly bad generators still abound, especially on microcomputers. Other generators widely used on medium-sized computers are perhaps not so spectacularly bad, but still fail some theoretical and/or empirical statistical tests, and/or generate easily detectable regular patterns. Fortunately, many applications appear quite robust to these defects. But with the rapid increase in desktop computing power, increasingly sophisticated simulation studies are being performed that require more and more "random" numbers and whose results are more sensitive to the quality of the underlying generator. For our statistical analysis we will use C++ to generate random number which gives satisfactory result and can be used for statistical purpose.
The sample code used to generate random numbers in C++ is given below: