Subject: bug#61267: shuf -i with negative numbers

From: Pádraig Brady <[email-masked]>
Date: Sat, 4 Feb 2023 12:09:25 +0000

tag 61267 notabug
close 61267
stop

comments below...

On 03/02/2023 22:31, [email-masked] wrote:
> hello
> 
> shuf -i option cannot handle negative numbers.
> examples:
>    $ shuf -i -10-20
>    $ shuf -i 0--20
> 
> don't know if it's a bug or a feature.

The input range needs to be unsigned
as documented in the info manual.
It should be easy enough to shift to the desired range,
for example:

   $ shiftn() { sed "s/\$/$1/" | bc; }
   $ shuf -i 0-10 | shiftn -5
   3
   -2
   0
   5
   2
   -5
   4
   -1
   -3
   1
   -4

cheers,
Pádraig