Re: feature request: sleep --random
Pádraig Brady wrote: > Pádraig Brady wrote: >> sleep $(seq .1 .1 4 | head -n $(($RANDOM%40 +1)) | tail -n1) > > Or more concisely using just coreutils logic: > > sleep $(seq .1 .1 4 | shuf | head -n1) Or save a pipe+process: sleep $(seq .1 .1 4 | shuf --head=1)
Re: feature request: sleep --random
Philip Rowlands wrote: > On Fri, 18 Sep 2009, Pádraig Brady wrote: > >> Pádraig Brady wrote: >>> sleep $(seq .1 .1 4 | head -n $(($RANDOM%40 +1)) | tail -n1) >> >> Or more concisely using just coreutils logic: >> >> sleep $(seq .1 .1 4 | shuf | head -n1) > > This still has the quantization effects which I'm trying to avoid. Jim's > perl suggestion would work well to ensure an even spread over the window > of time. > > $ perl -e 'sleep rand 4' > > is probably the cleanest / most efficient way to do this with existing > tools. right. Note the scheduler is still going to quantize your sleep values, so in practicality your probably not going to get smoother than: sleep $(seq .002 .002 4 | shuf | head -n1) cheers, Pádraig. p.s. That's another use case for sort --range
Re: feature request: sleep --random
On Fri, 18 Sep 2009, Pádraig Brady wrote: Pádraig Brady wrote: sleep $(seq .1 .1 4 | head -n $(($RANDOM%40 +1)) | tail -n1) Or more concisely using just coreutils logic: sleep $(seq .1 .1 4 | shuf | head -n1) This still has the quantization effects which I'm trying to avoid. Jim's perl suggestion would work well to ensure an even spread over the window of time. $ perl -e 'sleep rand 4' is probably the cleanest / most efficient way to do this with existing tools. Cheers, Phil
Re: feature request: sleep --random
Pádraig Brady wrote: > sleep $(seq .1 .1 4 | head -n $(($RANDOM%40 +1)) | tail -n1) Or more concisely using just coreutils logic: sleep $(seq .1 .1 4 | shuf | head -n1) cheers, Pádraig.
Re: feature request: sleep --random
Philip Rowlands wrote: > This would help with some work I'm doing today, but is it of general > interest? > > $ sleep --random 4.0 > > sleeps for a random amount of time up to and including the requested > value. The purpose is that on distributed systems it's disruptive to > have synchronized scripts all starting up together. One option is to > use the shell's $RANDOM if available, but it's lot of typing to get > true (vs coarsely quantized) randomness. How about this: sleep $(perl -le 'print rand 4') That should work with more shells, and is smooth.
Re: feature request: sleep --random
Philip Rowlands wrote: > This would help with some work I'm doing today, but is it of general > interest? > > $ sleep --random 4.0 > > sleeps for a random amount of time up to and including the requested > value. The purpose is that on distributed systems it's disruptive to > have synchronized scripts all starting up together. One option is to use > the shell's $RANDOM if available, but it's lot of typing to get true (vs > coarsely quantized) randomness. Be careful with random sleeps: http://www.stdlib.net/~colmmacc/2009/09/14/period-pain/ You're right that the existing is more verbose but it's also more general: sleep $(seq .1 .1 4 | head -n $(($RANDOM%40 +1)) | tail -n1) I'm not sure we should add this. cheers, Pádraig.
feature request: sleep --random
This would help with some work I'm doing today, but is it of general interest? $ sleep --random 4.0 sleeps for a random amount of time up to and including the requested value. The purpose is that on distributed systems it's disruptive to have synchronized scripts all starting up together. One option is to use the shell's $RANDOM if available, but it's lot of typing to get true (vs coarsely quantized) randomness. Phil