From: Eric Cook <llua@gmx.com>
To: zsh-workers@zsh.org
Subject: Re: $RANDOM in function in pipe do not get reseeded
Date: Thu, 30 Mar 2017 09:25:39 -0400 [thread overview]
Message-ID: <ea289ab7-a75b-fc93-e682-884486c52c20@gmx.com> (raw)
In-Reply-To: <20170330112523.GA28110@t420s.epfl.ch>
On 03/30/2017 07:25 AM, tharvik@gmail.com 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.
prev parent reply other threads:[~2017-03-30 13:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-30 11:25 tharvik
2017-03-30 13:25 ` Eric Cook [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ea289ab7-a75b-fc93-e682-884486c52c20@gmx.com \
--to=llua@gmx.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).