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

  • SEARCH
  • Home
  • 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

Lets say I have a function which takes some input structure and returns some
I want to make a common function which takes a control as an argument
We have an order form which takes credit cards from mobile browsers: <input type=number
I want to build a function which takes the sum of all rows in
jQuery has the .map() function which takes as input either an array or an
I was trying to make a function which takes a matrix as input and
I want to write some code which takes any positive, even number (greater than
I want to write a function which would return me a Vector of the
I want to call a function which is in another php class that I
I want to create a function which plot on screen a set of figures

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.