Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RandomVar

Represents a random variable with a uniform distribution between zero and one.

The random variable constructor may specify a seed value, which causes the random sequence to be repeatable.

Use the sample method to retrieve random values from RandomVar objects.

Hierarchy

Index

Constructors

Methods

Constructors

constructor

  • Initializes a new instance of the RandomVar class.

    Parameters

    • seed: number = null

      Optional value used to initialize the random sequence.

      If you omit the seed value, a random seed will be generated automatically and the random sequences will be different every time you run the simulation. If you do provide a seed value, be careful to avoid unintended correlations between different random variables. For example:

      // M/M/1: https://en.wikipedia.org/wiki/M/M/1_queue
      export class MM1 extends Simulation {
      
          // service times are exponentially distributed with mean 10 min and seed 1:
          serviceTime = new Exponential(10, 1);
      
          // inter-arrival times are exponentially distributed with mean 15 min
          // and the seed is 2 (to avoid correlations with the service times):
          this.interArrival = new Exponential(15, 2);
      
          // System and Server queues
          system = new Queue('System');
          server = new Queue('Server', 1);
      
          onStarting() {
              super.onStarting();
              this.generateEntities(MM1Entity, this.interArrival, 1e4);
          }
      }
      class MM1Entity extends Entity<MM1> {
          async script() {
              const sim = this.simulation;
              this.enterQueueImmediately(sim.system);
              await this.enterQueue(sim.server);
              await this.delay(sim.serviceTime.sample());
              this.leaveQueue(sim.server);
              this.leaveQueue(sim.system);
          }
      }
      

    Returns RandomVar

Methods

sample

  • sample(): number
  • Gets a random value uniformly distributed between zero and one.

    Returns number

Generated using TypeDoc