On Wed, Feb 9, 2011 at 9:41 AM, Rob Dixon <rob.di...@gmx.com> wrote:

> On 07/02/2011 21:30, Mike Blezien wrote:
>
>> I'm trying to come up with a function to send out X number of message per
>> day(24hr day) but we need to randomize the time factore each day. For
>> example if
>> 50 messages are scheduled to be sent out in 24 hr time period we want to
>> randomize the times they go out during this time period instead of a fixed
>> time
>> period.
>>
> <snip>

>
> The program below may be some help.
>
> Rob
>

That's an elegant solution. If I understand the code correctly, you're
treating the list of minutes in a day like a deck of cards. Each minute
represents one card. You shuffle the deck. The first 50 elements (cards) are
50 random times of the day.

while ($h < 24) {
>  push @times, sprintf '%02d:%02d', $h, $m;
>  ++$h, $m = 0 if ++$m >= 60;
> }
>

I assume that Mike (the original poster) would get 50 times by substituting
"[0..50]" in place of "[0..24]".

my @sample = (shuffle @times)[0..24];
>

And this last piece then sorts the 50 random times into chronological order
for the cron job. It's very clever.

print "$_\n" foreach sort @sample;


-- 
Robert Wohlfarth

Reply via email to