next up previous contents index
Next: 20.3 Integrals Up: 20. Mathematical Support Previous: 20.1.0.0.3 OTcl support

   
20.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 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:

UniformRandomVariable../ns-2/ranvar.h min_, max_
ExponentialRandomVariable../ns-2/expoo.h avg_
ParetoRandomVariable../ns-2/pareto.h avg_, shape_
ConstantRandomVariable val_
HyperExponentialRandomVariable../ns-2/ranvar.h avg_, cov_

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




2000-08-24