On Fri, Jan 06, 2023 at 12:58:48AM +0100, Rachel Roch wrote:
>
>
>
> 5 Jan 2023, 18:24 by [email protected]:
>
> > Namaste Rachel, Theo(s),
> >
> >> Sent: Thursday, January 05, 2023 at 5:50 PM
> >> From: "Theo de Raadt" <[email protected]>
> >> To: "Theo Buehler" <[email protected]>
> >> Cc: "Rachel Roch" <[email protected]>, "Misc" <[email protected]>
> >> Subject: Re: Is CRONTAB(5) random really random ?
> >>
> >> Theo Buehler <[email protected]> wrote:
> >>
> >> > On Thu, Jan 05, 2023 at 06:15:43PM +0100, Rachel Roch wrote:
> >> > > According to the docs :
> >> > >
> >> > > > A random value (within the legal range) may be obtained by using
> >> > > > the ???~??? character in a field.
> >> >
> >> > The random numbers are drawn once and then repeated regularly. This
> >> > behavior has always bothered me but never enough to spend the time
> >> > needed to fix it (it's not immediately obvious how to do it). A
> >> > workaround is to use a
> >> >
> >> > sleep $((RANDOM \% 512)) && run_whatever
> >> >
> >> > construct. The number to the right of the modulo should be a power of 2
> >> > to avoid modulo bias.
> >>
> >> Any solution would need to be careful, so that a operation doesn't run
> >> multiple times in an hour. Each column should be '0 + random % range',
> >> but multiple columns contain ~, it gets weird.
> >>
> >
> > The following thread may be helpful:
> >
> > "Regarding randomized times in crontab"
> > https://marc.info/?l=openbsd-misc&m=158705405304672&w=2
> >
> > Dhanyavaad,
> > Dharma Artha Kama Moksha
> >
>
> Thank you all for your insightful input, looks like the $RANDOM prefix idea
> is the only quick-fix to this.
>
> I didn't realise the random value was only set once. Maybe someone should
> update the man page accordingly ?
>
To be clear, it is "once per ~ occurrence in the crontab", not once
for all ~ or once per crontab line.
-Otto