0

Say I have certain events that happen one after another, and I want to be able to select a subset such as every 50th event and set it aside. But say I have no way of exactly knowing when the 50th event has occurred.

Would it be similar if i was to take a random number between 1..50 and if it equals 50, then set it aside?

I need to solve something similar and I am not sure how to select every 50th element that comes in when I dont have any information that I can use. Of course I could store a value in a database such as a count but I would rather not.

Also every event that comes in has no relation to the next or previous.

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
strangeQuirks
  • 4,761
  • 9
  • 40
  • 67
  • Do you have any code which generates, or handles, said events? – ChristianF Oct 12 '16 at 08:42
  • well no, its not the important part, the question I have is how can I take a random subset that is roughly equal to every 50th event. For example, people signup to a website, I want to take every 50th person and do something. However I cant use something such as an id and do a modulo – strangeQuirks Oct 12 '16 at 08:47
  • 1
    Possible duplicate of [how can I choose a random number but with a normal probability distribution in PHP?](http://stackoverflow.com/questions/15951563/how-can-i-choose-a-random-number-but-with-a-normal-probability-distribution-in-p) – GlennV Oct 12 '16 at 10:33

3 Answers3

1

Basically what you're saying, as I've understood it, is the following:

  • You have a set of events.
  • There is no relation between the events.
  • There is no order in the events.
  • There is no known state between the events.
  • The trigger is unknown.

Yet you, somehow, still want to be able to trigger upon an event related upon the state of their order of generation. In practice what you're saying is that you have three impossible situations that you'd like the computer to "read your mind" on, and then decide on a solution of which you yourself don't know.

That leads to the only logical answer I can give:
As the questions stands right now, what you are looking to do is impossible.

Solve the state engine, and trace the order and relation of the events, then you might have a chance of finding your solution. However, without you knowing what you want to do, no-one will be able to help you.

ChristianF
  • 2,068
  • 9
  • 14
0

You've made this very vague, so I can only give a vague answer. My first thought would be to create a counter variable.

$counter = 0;

Then each time an event occurs, you can add to it.

myEvent();
$counter++;

This of course then allows you to check whether the current event is the 50th.

if($counter == 50)
{
myEvent();
/* Whatever code "puts the event aside" */
$counter = 0;
}
else
{
myEvent();
$counter++;
}

Again, without some context this question is hard to answer but hopefully this helps.

PL200
  • 741
  • 6
  • 24
0

I would implement a while loop:

$Count = 0;

while ($Count != 50) {

$Count ++;

If($Count == 50) {//Whatever Happens Next; break;}

{

DatBundah
  • 27
  • 8