Generating poisson arrivals

There is something I didn't understand. I use the sample given from the cpp reference to generate numbers:

1
2
3
4
5
6
7
8
9
const int nrolls = 10; // number of experiments

std::default_random_engine generator;
std::poisson_distribution<int> distribution(4.1);

for (int i=0; i<nrolls; ++i){
int number = distribution(generator);
cout<<number<<" "<<endl;
}


(original code: http://www.cplusplus.com/reference/random/poisson_distribution/ )

This outputs: 2 3 1 4 3 4 4 3 2 3 and so on... First of all what those numbers mean? I mean do I have to sum them to create timing? For example: 2, (2+3)=5, (5+1)=6, (6+4)=10,..., and so on..

Secondly, my real question is, I need to produce both random arrivals for network packets and the size of packets. I mean, when the packets come and if packets come, what are the size of packets? How can I do that? I need something like that: http://i.hizliresim.com/dWmaGX.png
> std::poisson_distribution<int> distribution(4.1) ;
> This outputs: 2 3 1 4 3 4 4 3 2 3 and so on... First of all what those numbers mean?

It is the number of events (in this case number of packets arriving) per unit time (say, in each second), if the expected value (average) of the number of packets arriving per unit time (per second) is 4.1.
https://en.wikipedia.org/wiki/Poisson_distribution

The times (in seconds, continuing with the same example) between two consecutive packets would be given by an exponential distribution. https://en.wikipedia.org/wiki/Exponential_distribution

std::exponential_distribution<>: http://en.cppreference.com/w/cpp/numeric/random/exponential_distribution


> when the packets come and if packets come, what are the size of packets?

Use an appropriate truncated distribution, bounded in the range (minimum packet size, maximum packet size). For instance we can (crudely) simulate a truncated normal distribution by discarding samples that lie outside the range

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <random>
#include <cmath>
#include <iomanip>

int main()
{
    const double avg_packets_per_second = 4.1 ;
    const int min_packet_sz = 50 ;
    const int max_packet_sz = 760 ;
    const double variance = 300 ;

    std::exponential_distribution<double> inter_arrival_time( avg_packets_per_second ) ;
    std::normal_distribution<double> pkt_size( (min_packet_sz+max_packet_sz)/2.0, variance ) ;

    std::mt19937 rng( std::random_device{}() ) ;

    double time = 0 ;
    // generate 25 packets
    std::cout << std::fixed << std::setprecision(2) ;
    for( int i = 0 ; i < 25 ; ++i )
    {
        time += inter_arrival_time(rng) ;

        int sz ;
        do sz = std::round( pkt_size(rng) ) ;
        while( sz < min_packet_sz || sz > max_packet_sz ) ;

        std::cout << "at " << time << " seconds, packet with size "  << std::setw(3) << sz << " bytes\n" ;
    }
}

http://coliru.stacked-crooked.com/a/c9d764c29feb2212
Topic archived. No new replies allowed.