Generate (Poisson?) Random variable in real time

I have a program that works in real time with a variable frame rate, for example. can be 15 frames per second, can be 60 frames per second. I want the event to occur on average once every 5 seconds. Each frame, I want to call a function that takes time since the last frame as input, and returns True on average once every 5 seconds of elapsed time when it is called. I am doing something with the Poisson distribution .. how would I do it?

+3
source share
2 answers

It really depends on which distribution you want to use, everything you specified was average. I would, as you said, expect the Poisson distribution to suit your needs perfectly, but you also put a “uniform random variable” in the name, which is a different distribution, anyway, just go with the first one.

So, if the Poisson distribution is what you want, you can easily generate samples using the cumulative density function. Just follow the pseudo code here: Generating Poisson RVs , with 5 seconds being your value for lambda. Let me call this function Poisson_RN ().

The algorithm at this point is quite simple.

global float next_time = current_time()

boolean function foo()
if (next_time < current_time())
  next_time = current_time() + Poisson_RN();
  return true;
return false;
+4
source

, / , . true 1/(5 * fps), true 5 .

0

Source: https://habr.com/ru/post/1791913/


All Articles