A
A
Arjey W2017-04-07 22:47:04
PHP
Arjey W, 2017-04-07 22:47:04

How to randomly scatter, limited per day, the number of events by time ("happy hours")?

There are events.
They need to be scattered by $A count (max. count per day), create a so-called event plan for n number of days, or until the number of incoming events runs out.
So that during the day, randomly so that they fall on the so-called happy hours.
Hours - quantity as a percentage.
8-11 - 25%
12-16 - 35%
17-23 - 40%
Help, tell us how to implement this....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VisualIdeas, 2017-04-07
@VisualIdeas

Generation of a discrete random variable (like correctly named)
I would do it somehow. So:

$array=array(
'8,9,10,11' => 25,
'12,13,14,15,16' => 35,
'8,9,10,11' => 40
);

// . Для каждого дня:
$rand=mt_rand(0,99);
$sum=0;
foreach($array as $key=>$value) {
    if (($rand>=$sum)&&($rand<($sum + $value))) {
        // Временной промежуток этот $value
        // Если надо снова случайный час, то
       $hour = explode(',',$key);
       shuffle($hour);
       $hour = array_shift($hour);
       // $hour - определеный час
       break;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question