Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug/regression: tt(RANDOM) seed not updating when $RANDOM is used in a pipe



On 6/28/23, Jon Oster <jon.i.oster@xxxxxxxxx> wrote:
> In 5.8.1, $RANDOM seems not to update its state when the command $RANDOM
> was used in is piped somewhere. For example:
>
> # echo $RANDOM
> 18163
> # echo $RANDOM
> 23472
> # echo $RANDOM
> 27685
> # echo $RANDOM|cat
> 10178
> # echo $RANDOM|cat
> 10178
> # echo $RANDOM
> 10178
> # echo $RANDOM
> 17862

A simple workaround for this, whether you consider it a bug or a feature,
% () { echo $1 | cat } $RANDOM
21589
% () { echo $1 | cat } $RANDOM
301

or
% echo $RANDOM > >(cat)
1324
% echo $RANDOM > >(cat)
9460

-- 
Mikael Magnusson




Messages sorted by: Reverse Date, Date, Thread, Author