meme
meme

Reputation: 3

How to create random number every minute

I have a question. "random number of customers arriving for a check out is between 5 and 10 every minute." I need to put these customers in a list based on their order of their arrival time.

I don't know how to generate a random numbers of customers every minute, and I don't know how to assume their arrival time.

this is for Nachos server using c++ code and using threadtest.c code

Upvotes: -2

Views: 207

Answers (1)

doug
doug

Reputation: 4289

Use a Poison distribution. This creates a vector of 3600 ints each of which has the number of customers that came in during that second. The vector's index is the timestamp.

Keep in mind that there will be times when more than 1 customer comes in during any given second. If so each customer would have the same timestamp. Change the time resolution as desired. You can also just create a vector of tuples with time and customer_count and push an entry only one or more customers arrive at any given second. That's your assignment. This is to illustrate a Poisson distribution.

#include <iostream>
#include <random>
#include <vector>

int main()
{
    std::random_device rd;
    std::mt19937 gen(rd());
    std::poisson_distribution<> d(5/60.0);  // set average for Poisson distribution for 5 per minute

    std::vector<int> customers_at_each_second;
    int total_customers = 0;
    for (int i = 0; i < 3600; i++)
    {
        int customers_at_this_second = d(gen);
        customers_at_each_second.push_back(customers_at_this_second);
        total_customers += customers_at_this_second;
    }
    std::cout << "Total Customers in the hour " << total_customers << '\n';
}

Upvotes: 1

Related Questions