Aggie Student Toolkit — Load Balancer CSCE 412 Project 4
Arnav Fotedar · Fall 2026 · C++ load balancer simulation
Loading...
Searching...
No Matches
RequestGenerator Class Reference

Produces random requests from a single seeded Mersenne Twister engine. More...

#include <RequestGenerator.h>

Public Member Functions

 RequestGenerator (const GeneratorSettings &settings, std::uint32_t seed)
 Creates a generator.
Request makeRequest (unsigned long cycle)
 Creates one random request.
std::vector< Request > makeInitialBatch (std::size_t count, unsigned long cycle)
 Creates the initial queue contents.
std::vector< Request > arrivalsFor (unsigned long cycle)
 Creates the random arrivals for one clock cycle.
double rateAt (unsigned long cycle) const
 Returns the mean arrival rate at a given cycle.
const GeneratorSettings & settings () const
const GeneratorStats & stats () const
std::uint32_t seed () const
const std::vector< Request > & samples () const

Detailed Description

Produces random requests from a single seeded Mersenne Twister engine.

Every random choice in the simulation comes from this class: source and destination IPv4 addresses, task length (uniform between the configured minimum and maximum), job type, and the number of new arrivals each cycle (Poisson distributed). Using one logged seed makes every run repeatable.

Definition at line 57 of file RequestGenerator.h.

Constructor & Destructor Documentation

◆ RequestGenerator()

RequestGenerator::RequestGenerator ( const GeneratorSettings & settings,
std::uint32_t seed )

Creates a generator.

Parameters
settingsTask-length range, arrival rate and job mix.
seedSeed for the random engine; the same seed reproduces the same run.

Definition at line 17 of file RequestGenerator.cpp.

Member Function Documentation

◆ makeRequest()

Request RequestGenerator::makeRequest ( unsigned long cycle)

Creates one random request.

Parameters
cycleArrival cycle stamped on the request.
Returns
A new request with a unique id.

Definition at line 45 of file RequestGenerator.cpp.

◆ makeInitialBatch()

std::vector< Request > RequestGenerator::makeInitialBatch ( std::size_t count,
unsigned long cycle )

Creates the initial queue contents.

Parameters
countNumber of requests to create.
cycleArrival cycle stamped on each request (normally 0).
Returns
The requests in generation order.

Definition at line 57 of file RequestGenerator.cpp.

◆ arrivalsFor()

std::vector< Request > RequestGenerator::arrivalsFor ( unsigned long cycle)

Creates the random arrivals for one clock cycle.

The number of arrivals follows a Poisson distribution whose mean is rateAt(cycle), so most cycles bring zero or one request and occasional cycles bring bursts.

Parameters
cycleCurrent clock cycle.
Returns
Zero or more new requests.

Definition at line 67 of file RequestGenerator.cpp.

◆ rateAt()

double RequestGenerator::rateAt ( unsigned long cycle) const

Returns the mean arrival rate at a given cycle.

The rate follows a sine wave around GeneratorSettings::arrivalRate to model busy and quiet periods (for example day and night traffic): rate(t) = arrivalRate x (1 + waveAmplitude x sin(2 pi t / wavePeriod)).

Parameters
cycleClock cycle.
Returns
Mean requests per cycle, never negative.

Definition at line 27 of file RequestGenerator.cpp.

◆ settings()

const GeneratorSettings & RequestGenerator::settings ( ) const
Returns
The settings used by this generator.

Definition at line 108 of file RequestGenerator.cpp.

◆ stats()

const GeneratorStats & RequestGenerator::stats ( ) const
Returns
Statistics describing everything generated so far.

Definition at line 112 of file RequestGenerator.cpp.

◆ seed()

std::uint32_t RequestGenerator::seed ( ) const
Returns
The seed the engine was created with.

Definition at line 116 of file RequestGenerator.cpp.

◆ samples()

const std::vector< Request > & RequestGenerator::samples ( ) const
Returns
The first few requests generated, kept as a sample for the log.

Definition at line 120 of file RequestGenerator.cpp.


The documentation for this class was generated from the following files: