op_dist_uniform()
Abstract
Generates a random value that is uniformly distributed in a bounded range starting at 0.0 and extending to (but not including) the specified limit.
Syntax
op_dist_uniform (limit)
| Argument | Type | Description |
|---|---|---|
limit |
double |
Bound of the range of uniformly distributed value |
Return Type
double
Generated uniform random value.
This value is between 0.0, inclusive and the specified limit, exclusive.
Example
Excerpt from: example model (models/std/eth_net); process model (eth_mac); state (BACKOFF); enter execs.
/* compute backoff interval using truncated binary exponential process; */
/* the unit for retransmission scheduling is the slot time and the upper */
/* bound is based on the # of transmissions to date of the current frame */
/* if this is the first attempt, there are two possible backoff slots. */
if (attempts == 1) max_backoff = 2;
/* otherwise the number of possible slots grows exponentially until */
/* it exceeds a fixed limit. */
else if (attempts <= BACKOFF_LIMIT)
max_backoff = max_backoff * 2;
/* obtain a uniformly distributed random integer between 0 and backoff limit */
backoff_slots = op_dist_uniform (max_backoff);
/* set a timer for the end of the backoff interval */
op_intrpt_schedule_self (op_sim_time () + backoff_slots * SLOT_TIME, 0);
Details
The random number stream used by this KP is generated by calls to the BSD random() procedure, and is shared by all Dist package KPs and by the generator modules. The random number stream is dependent on an initial seed, which can be altered via the simulation environment attribute “seed” (see Chapter 1 “Executing a Discrete Event Simulation” on page 1 for more information). Simulation results are repeatable if the simulation inputs are identical, including the same random seed.
If a negative value is specified for the limit argument, the returned value will be a uniformly distributed negative number <= 0 and greater than limit.
Purpose
Provides a mechanism for obtaining a uniformly-distributed random number, for general modeling purposes. An example use would be for computing a random time-out used by a data link protocol.
Errors
- No errors are trapped.
Reference
- Use the KP op_dist_load() to load a probability distribution
- Use the KP op_dist_outcome() to obtain a stochastic value based on a loaded probability distribution