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 3964550
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:20:52+00:00 2026-05-20T03:20:52+00:00

I want a function which takes, as input, the number of seconds elapsed since

  • 0

I want a function which takes, as input, the number of seconds elapsed since the last time it was called, and returns true or false for whether an event should have happened in that time period. I want it such that it will fire, on average, once per X time passed, say 5 seconds. I also am interested if it’s possible to do without any state, which the answer from this question used.

I guess to be fully accurate it would have to return an integer for the number of events that should’ve happened, in the case of it being called once every 10*X times or something like that, so bonus points for that!

  • 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-20T03:20:53+00:00Added an answer on May 20, 2026 at 3:20 am

    It sounds like you’re describing a Poisson process, with the mean number of events in a given time interval is given by the Poisson distribution with parameter lambda=1/X.

    The way to use the expression on the latter page is as follows, for a given value of lambda, and the parameter value of t:

    1. Calculate a random number between zero and one; call this p
    2. Calculate Pr(k=0) (ie, exp(-lambda*t) * (lambda*t)**0 / factorial(0))
    3. If this number is bigger than p, then the number of simulated events is 0. END
    4. Otherwise, calculate Pr(k=1) and add it to Pr(k=0).
    5. If this number is bigger than p, then the answer is 1. END
    6. …and so on.

    Note that, yes, this can end up with more than one event in a time period, if t is large compared with 1/lambda (ie X). If t is always going to be small compared to 1/lambda, then you are very unlikely to get more than one event in the period, and so the algorithm is simplified considerably (if p < exp(-lambda*t), then 0, else 1).

    Note 2: there is no guarantee that you will get at least one event per interval X. It’s just that it’ll average out to that.

    (the above is rather off the top of my head; test your implementation carefully)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to call a function (which calculates my version number) when my NSIS
I was trying to make a function which takes a matrix as input and
I want to write a function that accepts a parameter which can be either
Django view points to a function, which can be a problem if you want
I have a base class Foo that has an Update() function, which I want
I want a simple function that receives a string and returns an array of
I want to write a function in Python that returns different fixed values based
There is a small program which takes input from users on a prompt. It
I am trying to create a function which takes a shell command as an
I'm writing a C/C++ DLL and want to export certain functions which I've done

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.