There are events.

They need to pitch in $A, count(max per day), to create so-called event plan for n number of days, or until the number of incoming events.

So during the day, randomly so that they fall out on the so-called happy hours.

Watch the number as a percentage.

8-11 - 25%

12-16 - 35%

17-23 - 40%

Help, tell me how you can implement it....

They need to pitch in $A, count(max per day), to create so-called event plan for n number of days, or until the number of incoming events.

So during the day, randomly so that they fall out on the so-called happy hours.

Watch the number as a percentage.

8-11 - 25%

12-16 - 35%

17-23 - 40%

Help, tell me how you can implement it....

asked June 27th 19 at 15:20

1 answer

answered on June 27th 19 at 15:22

Generation of discrete random variable (like the right to call)

I would have done something. so:

I would have done something. so:

```
$array=array(
'8,9,10,11' => 25,
'12,13,14,15,16' => 35,
'8,9,10,11' => 40
);
// . For each day:
$rand=mt_rand(0,99);
$sum=0;
foreach($array as $key=>$value) {
if (($rand>=$sum)&&($rand<($sum + $value))) {
// Time period is this $value
// If need to back random hours
$hour = explode(',',$key);
shuffle($hour);
$hour = array_shift($hour);
// $hour - specific hour
break;
}
}
```

Find more questions by tags AlgorithmsPHPProgramming