RANDOM NUMBERS AND STREAMS
The CSIM library has several functions which can be used to generate random variates from specified
distributions. Most of these functions use prob (see below) to generate a uniformly distributed random sample
between (but not including) 0 and 1 which is then used as the basis for a random sample from some other
distribution.
Generating Random Values from the Standard Stream
To generate a random variate using an Erlang_k distribution:
rand_num = erlang(mean, variance);
Where:
rand_num - is set to a random value drawn from an Erlang-k distribution (type double)
mean - is the desired mean for the distribution (type double)
variance - is the desired variance for the distribution (type double)
Notes:
The value of k for this Erlang-k distribution is (mean*(mean/variance) + 0.5).
To generate a random variate using a negative exponential distribution:
rand_num = expntl(mean);
Where:
rand_num - is set to a random value drawn from a negative exponential distribution (type double)
mean - is the desired mean for the distribution (type double)
To generate a random variate using a hyperexponential distribution:
rand_num = hyperx(mean, variance);
Where:
rand_num - is set to a random value drawn from a hyperexponential distribution (type double)
mean - is the desired mean for the distribution (type double)
variance - is the desired variance for the distribution (type double)
To generate a random variate using a normal distribution:
rand_num = normal(mean, std_dev);
Where:
rand_num - is set to a random value drawn from a hyperexponential distribution (type double)
mean - is the desired mean for the distribution (type double)
std_dev - is the desired standard deviation for the distribution (type double)
To generate a random variate using a uniform distribution from 0 to 1:
rand_num = prob();
Where:
rand_num - is set to a random value drawn from a uniform (0,1) distribution (type double)
Notes:
rand_num will never be exactly 0 or 1.
prob calls the C function rand().
To generate a random integer using a uniform distribution between two arbitrary integers:
rand_int = random(low_int, high_int);
Where:
rand_int - is set to a random value drawn from a uniform [low_int,high_int] distribution (type long)
low_int - is the lowest integer in the range of values to be generated (type long)
high_int - is the highest integer in the range of values to be generated (type long)
Notes:
rand_num can be low_int or high_int as well as any integer between them.
To generate a random number using a uniform distribution between two arbitrary floating
point numbers:
rand_num = uniform(low, high);
rand_num - is set to a random value drawn from a uniform (low,high) distribution (type double)
low - is the lowest integer in the range of values to be generated (type double)
high - is the highest integer in the range of values to be generated (type double)
Notes:
rand_num will never be exactly low or high.
Resetting the Standard Stream
To cause the standard random number stream to be reinitialized:
reset_prob(index);
Where:
index - is the relative number from the beginning of the random number stream at which you want the
numbers to restart (type long). In other words, to restart the stream at the nth number in that stream,
specify n as index. In particular, if index is 1, the sequence of random numbers will start again at the
beginning.
Declaring and Initializing “Custom” Random Number Streams:
In addition to the generating random values from the standard random number stream, CSIM also supports
“custom” streams of random numbers. A “custom” stream is a sequence of pseudo random numbers based on
a user-specified seed. If two streams are initialized to the same seed, then the two sequences of pseudo
random numbers will be the same. One possible use of this is to assign different streams to different service
functions. Used this way, each sequence of service times will be the same, regardless of changes to other
parts of the model.
To declare a random number stream:
STREAM st;
Where:
st - is the variable name representing the random number stream (type STREAM)
Notes:
A random number stream must be initialized via the stream_init statement before it can be used in any
other statement.
To initialize a random number stream:
st = stream_init(seed);
Where:
st - is the variable name representing the random number stream (type STREAM)
seed - is the indication of which random number stream should be used (type long)
Notes:
The same seed will always cause the same sequence of random numbers to be generated (for a given
distribution). This guarantees repeatability at the same time that it allows the flexibility of having different
numbers generated for different processes (for example) even when the same distribution is used.
Generating Random Values from a “Custom” Stream
To generate a random variate using an Erlang_k distribution:
rand_num = erlang(st, mean, variance);
Where:
st - is the variable name representing the random number stream (type STREAM)
rand_num - is set to a random value drawn from an Erlang-k distribution (type double)
mean - is the desired mean for the distribution (type double)
variance - is the desired variance for the distribution (type double)
Notes:
The value of k for this Erlang-k distribution is (mean*(mean/variance) + 0.5).
To generate a random variate using a negative exponential distribution:
rand_num = expntl(st, mean);
Where:
st - is the variable name representing the random number stream (type STREAM)
rand_num - is set to a random value drawn from an Erlang-k distribution (type double)
mean - is the desired mean for the distribution (type double)
To generate a random variate using a hyperexponential distribution:
rand_num = hyperx(st, mean, variance);
Where:
st - is the variable name representing the random number stream (type STREAM)
rand_num - is set to a random value drawn from a hyperexponential distribution (type double)
mean - is the desired mean for the distribution (type double)
variance - is the desired variance for the distribution (type double)
To generate a random variate using a normal distribution:
rand_num = normal(st, mean, std_dev);
Where:
st - is the variable name representing the random number stream (type STREAM)
rand_num - is set to a random value drawn from a hyperexponential distribution (type double)
mean - is the desired mean for the distribution (type double)
std_dev - is the desired standard deviation for the distribution (type double)
To generate a random variate using a uniform distribution from 0 to 1:
rand_num = prob(st);
Where:
st - is the variable name representing the random number stream (type STREAM)
rand_num - is set to a random value drawn from a uniform (0,1) distribution (type double)
Notes:
rand_num will never be exactly 0 or 1.
prob calls the C function rand().
To generate a random integer using a uniform distribution between two arbitrary integers:
rand_int = random(st, low_int,high_int);
Where:
st - is the variable name representing the random number stream (type STREAM)
rand_int - is set to a random value drawn from a uniform [low_int,high_int] distribution (type long)
low_int - is the lowest integer in the range of values to be generated (type long)
high_int - is the highest integer in the range of values to be generated (type long)
Notes:
rand_num can be low_int or high_int as well as any integer between them.
To generate a random number using a uniform distribution between two arbitrary floating
point numbers:
rand_num = uniform(st, low, high);
Where:
st - is the variable name representing the random number stream (type STREAM)
rand_num - is set to a random value drawn from a uniform (low,high) distribution (type double)
low - is the lowest integer in the range of values to be generated (type double)
high - is the highest integer in the range of values to be generated (type double)
Notes:
rand_num will never be exactly low or high.
Resetting a “Custom” Random Number Stre
To cause a random number stream to be reinitialized:
reset_prob(st ,index);
Where:
st - is the variable name representing the random number stream (type STREAM)
index - is the relative number from the beginning of the random number stream at which you want the
numbers to restart (type long). In other words, to restart the stream at the nth number in that stream,
specify n as index. In particular, if index is 1, the sequence of random numbers will start again at the
beginning.