26.2 Random Variables

The RandomVariable../ns-2/ranvar.h provides a thin layer of functionality on top of the base random number generator and the default random number stream. It is defined in ~ns/ranvar.h:

  class RandomVariable : public TclObject {
  public:
        virtual double value() = 0;
        int command(int argc, const char*const* argv);
        RandomVariable();
  protected:
        RNG* rng_;
  };

Classes derived from this abstract class implement specific distributions. Each distribution is parameterized with the values of appropriate parameters. The value method is used to return a value from the distribution.

The currently defined distributions, and their associated parameters are:

UniformRandomVariabletools/ranvar.h min_, max_
ExponentialRandomVariabletools/ranvar.h avg_
ParetoRandomVariabletools/ranvar.h avg_, shape_
ParetoIIRandomVariabletools/ranvar.h avg_, shape_
ConstantRandomVariabletools/ranvar.h val_
HyperExponentialRandomVariabletools/ranvar.h avg_, cov_
NormalRandomVariabletools/ranvar.h avg_, std_
LogNormalRandomVariabletools/ranvar.h avg_, std_

The RandomVariable class is available in OTcl. For instance, to create a random variable that generates number uniformly on [10, 20]:

        set u [new RandomVariable/Uniform]
        $u set min_ 10
        $u set max_ 20
        $u value
By default, RandomVariable objects use the default random number generator described in the previous section. The use-rng method can be used to associate a RandomVariable with a non-default RNG:
        set rng [new RNG]
        $rng seed 0

        set e [new RandomVariable/Exponential]
        $e use-rng $rng

Tom Henderson 2014-12-17