From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 22174 invoked from network); 25 Feb 2023 23:22:34 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 25 Feb 2023 23:22:34 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Subject:Cc:To:From:Date: References:In-Reply-To:Message-Id:Mime-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=LqFEMy4Wcp5llQsY1qry6ULWRNU/u6U5MKzrGDVbij8=; b=GKeKBlI/mepvkr7xWNbDpvKOUm P1yhV3bfwc7DBim/WiwvSE7K+r9qy6sN0bkkGzDer6e7q70ZkxVRMueQMfz+uEpMXMZcEMRN4Bp84 HIwYN2hYh+SltF76jqW3D+oil6Y1qFywxPaUFQSed8A0DyuoUtbWH3/rMllRr5F630X+PF3CrgKwg lbmxfPztXuYyIeJsNR9mWyU7qqL9/SAhb8cfjVrNhCkrKg2MZ5p6QoPzuyasaeToKwthtOymZWZjm m3BBZhQhIQsP1xcJbBRTq+b7uQTwRA0QP8B/kiuzatgFp7J56SWyCiFyvWSfwfFOgwEgU+A9EkeLT /Ul11cAA==; Received: by zero.zsh.org with local id 1pW3sA-000FDb-3I; Sat, 25 Feb 2023 23:22:34 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1pW3rv-000EvH-Ak; Sat, 25 Feb 2023 23:22:19 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailauth.nyi.internal (Postfix) with ESMTP id B4A3427C0054; Sat, 25 Feb 2023 18:22:17 -0500 (EST) Received: from imap48 ([10.202.2.98]) by compute1.internal (MEProxy); Sat, 25 Feb 2023 18:22:17 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudekjedgtdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfgjfhffhffvvefutgesth dtredtreerjeenucfhrhhomhepnfgrfihrvghntggvucggvghljoiiqhhuvgiiuceolhgr rhhrhihvseiishhhrdhorhhgqeenucggtffrrghtthgvrhhnpefhtedthfelhedtvefgie fhtefftdegudffteeiheejtdevudeiheeukefgffetffenucffohhmrghinhepshhouhhr tggvfhhorhhgvgdrihhonecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomheplhgrrhhrhihvodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithih qdduudehudekjeejtdegqdduudelvdejfeekhedqlhgrrhhrhihvpeepiihshhdrohhrgh esfhgrshhtmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: iaa214773:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 84A9131A0063; Sat, 25 Feb 2023 18:22:17 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-172-g9a2dae1853-fm-20230213.001-g9a2dae18 Mime-Version: 1.0 Message-Id: <97de94e6-ec50-4f38-962a-c066593bccbf@app.fastmail.com> In-Reply-To: <010701868ad0a7e8-be8c1ddd-a63c-4002-926a-b7ba25a0cebb-000000@eu-central-1.amazonses.com> References: <010701868ad0a7e8-be8c1ddd-a63c-4002-926a-b7ba25a0cebb-000000@eu-central-1.amazonses.com> Date: Sat, 25 Feb 2023 18:21:56 -0500 From: =?UTF-8?Q?Lawrence_Vel=C3=A1zquez?= To: Sheogorath Cc: zsh-workers@zsh.org Subject: Re: Bug report: Strange behaviour with random, sort and uniq Content-Type: text/plain X-Seq: 51480 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Sat, Feb 25, 2023, at 6:02 PM, Sheogorath wrote: > I was running the following command in a terminal: > > for i in $(seq 0 100); do echo $((1 + RANDOM % 6)); done | sort | uniq > -c > > When run twice after each other, it produces the same output: This command uses RANDOM in a subshell. https://zsh.sourceforge.io/Doc/Release/Parameters.html#index-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. > However, this changes, as soon as one run the command without the 'sort > | uniq -c' piping: > > for i in $(seq 0 100); do echo $((1 + RANDOM % 6)); done This command does not use RANDOM in a subshell. > I also validated, that this behaviour doesn't exist in bash. RANDOM works differently in bash. -- vq