Re: Is CRONTAB(5) random really random ?
On Fri, Jan 06, 2023 at 12:58:48AM +0100, Rachel Roch wrote: > > > > 5 Jan 2023, 18:24 by purushar...@gmx.com: > > > Namaste Rachel, Theo(s), > > > >> Sent: Thursday, January 05, 2023 at 5:50 PM > >> From: "Theo de Raadt" > >> To: "Theo Buehler" > >> Cc: "Rachel Roch" , "Misc" > >> Subject: Re: Is CRONTAB(5) random really random ? > >> > >> Theo Buehler 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
Re: Is CRONTAB(5) random really random ?
5 Jan 2023, 18:24 by purushar...@gmx.com: > Namaste Rachel, Theo(s), > >> Sent: Thursday, January 05, 2023 at 5:50 PM >> From: "Theo de Raadt" >> To: "Theo Buehler" >> Cc: "Rachel Roch" , "Misc" >> Subject: Re: Is CRONTAB(5) random really random ? >> >> Theo Buehler 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 ?
Re: Is CRONTAB(5) random really random ?
Namaste Rachel, Theo(s), > Sent: Thursday, January 05, 2023 at 5:50 PM > From: "Theo de Raadt" > To: "Theo Buehler" > Cc: "Rachel Roch" , "Misc" > Subject: Re: Is CRONTAB(5) random really random ? > > Theo Buehler 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 usingthe > > > > ‘~’ 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
Re: Is CRONTAB(5) random really random ?
Theo Buehler 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 usingthe > > > ‘~’ 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.
Re: Is CRONTAB(5) random really random ?
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 usingthe ‘~’ > > 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.
Re: [SPAM?] Is CRONTAB(5) random really random ?
Am Do., 5. Jan. 2023 um 18:16 Uhr schrieb Rachel Roch : > Especially given three of my crontab fields are supposed to be random > (minute, hour, day-of-month) I would expect to see at least one of the three > to be different ?!? AFAIK there is only one random value and it's created at startup of the daemon. Best Martin
Is CRONTAB(5) random really random ?
According to the docs : > A random value (within the legal range) may be obtained by usingthe ‘~’ > character in a field. However I've been running release versions of OpenBSD with the following definition: ~ ~ ~ * * /my/task/goes/here && /usr/bin/logger -t foo "Task done" Feb 18 18:09:01 foobar foo: Task done Mar 18 18:09:01 foobar foo: Task doneMar 24 23:42:01 foobar foo: Task doneApr 20 11:41:01 foobar foo: Task doneMay 16 18:24:01 foobar foo: Task doneJun 6 17:24:01 foobar foo: Task doneJul 6 17:24:01 foobar foo: Task doneAug 6 17:24:01 foobar foo: Task doneSep 6 17:24:01 foobar foo: Task doneOct 6 17:24:01 foobar foo: Task doneOct 31 08:44:01 foobar foo: Task doneNov 19 12:02:01 foobar foo: Task doneDec 19 12:02:02 foobar foo: Task done Surely it would be clutching at straws to describe an event happening at exactly the same time 5 months in a row (Jun–Oct) as genuinely statistically random ? The same with Nov & Dec. Especially given three of my crontab fields are supposed to be random (minute, hour, day-of-month) I would expect to see at least one of the three to be different ?!?