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 16:10, Jon Oster wrote:
In 5.8.1, $RANDOM seems not to update its state when the command $RANDOM
was used in is piped somewhere. For example:

Is this considered a bug? Or is it intended behaviour? Personally, I'd
argue it's a bug. Unfortunately, my C isn't good enough to try to fix and
submit a patch myself, but I tried to make this bug report as helpful as
possible.

[1] https://sourceforge.net/p/zsh/code/ci/faf0035e532cde45528806e7a05ad28a0ab7c0fb/


RANDOM <S>
       A  pseudo-random integer from 0 to 32767, newly generated each time this parame‐
       ter is referenced.  The random number generator can be seeded by assigning a nu‐
       meric value to RANDOM.

       The  values  of  RANDOM form an intentionally-repeatable pseudo-random sequence;
       subshells that reference RANDOM will result in  identical  pseudo-random  values
       unless  the  value  of RANDOM is referenced or seeded in the parent shell in be‐
       tween subshell invocations.


The LHS of the pipe should be a subshell, so the behavior is intentional.
RANDOM has be documented to work that way since it's introduction and this is commonly
misreported as a bug.




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