0% found this document useful (0 votes)
65 views

Random Number Generators

This document discusses random number generators and randomness. It defines a random number generator as a computation that generates a sequence of numbers that appear random without any pattern. True random numbers are generated from physical phenomena like dice rolls, while pseudo-random numbers use algorithms to produce long sequences that appear random but are ultimately predictable if the seed is known. The document provides examples of C++ code to generate pseudo-random integers and discusses applications of random number generators like simulations.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Random Number Generators

This document discusses random number generators and randomness. It defines a random number generator as a computation that generates a sequence of numbers that appear random without any pattern. True random numbers are generated from physical phenomena like dice rolls, while pseudo-random numbers use algorithms to produce long sequences that appear random but are ultimately predictable if the seed is known. The document provides examples of C++ code to generate pseudo-random integers and discusses applications of random number generators like simulations.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Randomness and rand

number generators

A random number generator


(RNG) is a computation designed to
generate a sequence of numbers or
symbols that lack any pattern, i.e.
appear random.
Random numbers need to be un
predictable

Methods used

dice
Flipping a coin
shuffling of playing cards
Slot machines (used in lotteries).etc

Because of the mechanical nature of these


techniques, generating large numbers of
sufficiently random numbers (important in
statistics) required a lot of work and/or time

Thus, results would sometimes be


collected and distributed as random
number tables

Types of RN
a) True RN
some physical phenomenon that is
expected to be random
Eg. Moving a mouse, throwing a dice,
sound parterns
They are unpredictable.

b) Pseudo random numbers


uses computational algorithm that
can produce long sequences of
apparently random results
determined by an initial value called
a seed
These types of generators do not
typically rely on sources of naturally
occurring entropy

Speudo RN cont
A "random number generator" based
solely on deterministic computation
cannot be regarded as a "true" random
number generator in the purest sense of
the word, since their output is inherently
predictable if all seed values are known
are algorithms that can automatically
create long runs of numbers with good
random properties but eventually the
sequence repeats

Eg.c++ code for SRNG


#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main()
{
srand((unsigned)time(0));
int random_integer = rand();
cout << random_integer << endl;
}
Note: srand is called once.

Another
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main()
{
srand((unsigned)time(0));
int random_integer;
for(int index=0; index<20; index++)
{
random_integer = (rand()%10)+1;
cout << random_integer << endl;
}
}

Applications of RNG
In applications where numbers
shouldnt be deterministic.eg.airtime
To generate a random report
depending on the random input. This
tries to represent the real world
randomness

Process Oriented Simulation

Process Oriented Simulation

Focus simulation program around behavior of entities


Aircraft: arrives, waits for runway, lands, departs

Process-oriented simulation
Process: thread of execution describing entity behavior over time
Resources: shared resource used by entities (e.g., runway)

Execution: alternate between simulation computations at


a single instant of simulation time, and advanced in
simulation time (no computation)

Simulation Primitives

Primitives needed to advance simulation time


AdvanceTime(T): advance T units of simulation
time
Also called hold
ex: AdvanceTime(R) to model using runway R units of
simulation time

WaitUntil(p): simulation time advances until


predicate p becomes true
Predicate based on simulation variables that can be
modified by other simulation processes
Ex: WaitUntil(RunwayFree) to wait until runway becomes
available for landing

You might also like