Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: $RANDOM in function in pipe do not get reseeded
On 03/30/2017 07:25 AM, tharvik@xxxxxxxxx wrote:
> Hello,
>
> There is some strange behavior with $RANDOM, because you don't
> seed after forking.
>
> For a testcase, here you go
> --
> Define a function echoing the value of $RANDOM
> ```
> get_random() {
> echo "${RANDOM}"
> }
> ```
> Run it trough a pipe
> ```
> get_random | cat
> ```
> If you run it multiple times, the output is the same.
> --
>
> There is the patch linked, which fixes it.
>
> Have a nice day!
>
from zshparam:
RANDOM <S>
A pseudo-random integer from 0 to 32767, newly generated each time this parameter is referenced. The random number
generator can be seeded by assigning a numeric 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
between subshell invocations.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author