Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6878297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:42:22+00:00 2026-05-27T04:42:22+00:00

I am trying to create a random hello world function based on the poisson

  • 0

I am trying to create a random “hello world” function based on the poisson arrival. In the code below, I define that the average mean (Lamda) is 5. And I want the time to elapse from 1 – 5 second, and keep track of it.

Based on an opensource project, seagull in this image here and here, I can see that for the same time, but different mean, the more it random occurences of the traffic (in my case, the “hello world”). But for my case, it just getting random sleep time, but the number of Hello World is the same.

How can I achieve the idea based on the images like what I use above. Is this the correct way of doing Poisson distribution for random generator? I saw the algorithm for Poisson based on Knuth

Thank you for the help.. Sorry for my bad english.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <string.h>
#include <time.h>

int poisson(double lambda){
  int k=0;
  double L=exp(-lambda), p=1;
  do {
    ++k;
    p *= rand()/(double)INT_MAX;
  } while (p > L);
  return --k;
}

int main()
{
int i=0; 
int val=0;
time_t timer;
char buffer[25];
struct tm* val_time;



    /*For time= 0 until time=10*/
    for  (i=0; i<10; i++)
    {
    printf("Hello World\n");

    /*To print the time*/
    time(&timer);
    val_time = localtime(&timer);
    strftime(buffer, 25, "%Y:%m:%d%H:%M:%S", val_time);
    puts(buffer);

    sleep(poisson(2)); /*interarrival process*/
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:42:23+00:00Added an answer on May 27, 2026 at 4:42 am

    I think the INT_MAX is in error, make that:

        p *= rand()/(double)RAND_MAX;
    

    Also, as long as the loop is bounded at 10, you’ll not get more hellos. What do you expect?

    Here is my full C++11 (not C!) version of the program:

    See it live on https://ideone.com/viZi3 (Note it soft-fails with Time limit exceeded there, because of obvious time-constraints on IdeOne)

    #include <iostream>
    #include <random>
    #include <chrono>
    #include <iomanip>
    
    static std::mt19937 rng;
    static std::poisson_distribution<int> poisson(2.0);
    
    typedef std::chrono::high_resolution_clock Clock;
    typedef std::chrono::time_point<Clock> Time;
    
    int main()
    {
        const Time finish_pole = Clock::now() + std::chrono::seconds(10);
    
        for (Time now = Clock::now(); now <= finish_pole; now = Clock::now())
        {
            std::cout << "Hello World\n";
    
            std::time_t now_c = Clock::to_time_t(now);
    #if CXX11_SUPPORT_COMPLETE
            std::cout << std::put_time(std::localtime(&now_c), "%F %T") << std::endl;
    #else
            char buffer[25];
            strftime(buffer, 25, "%Y:%m:%d%H:%M:%S", localtime(&now_c));
            std::cout << buffer << std::endl;
    #endif
    
            sleep(poisson(rng)); /*interarrival process*/
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a function that generates a random integer out of
I'm trying to figure out a way to create random numbers that feel random
I'm trying to create a fairly simple piece of JavaScript that displays a random
I'm trying to create a simple loop that adds a random number of stars,
im trying to create a block that shows a random image from a pool
I'm trying to create a unique id that's random. This solution was suggested, but
I'm trying to create code in processing that allows for runs of a certain
today I am basically trying to create some JAVA code that moves an actor
I am trying to create a dynamic chart for my random generator that keeps
I'm trying to create a trigger that will associate an unique random string to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.