zsh-workers
 help / color / mirror / code / Atom feed
From: Sheogorath <zsh@sheogorath.shivering-isles.com>
To: zsh-workers@zsh.org
Subject: Bug report: Strange behaviour with random, sort and uniq
Date: Sat, 25 Feb 2023 23:02:55 +0000	[thread overview]
Message-ID: <010701868ad0a7e8-be8c1ddd-a63c-4002-926a-b7ba25a0cebb-000000@eu-central-1.amazonses.com> (raw)

Hello ZSH maintainers,

I found a quite strange bug in my current installation. I tried to do
some virtual dice flips and something strange appeared.

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:

Example:
$ for i in $(seq 0 100); do echo $((1 + RANDOM % 6)); done | sort |
uniq -c
     12 1
     17 2
     22 3
     19 4
     16 5
     15 6

$ for i in $(seq 0 100); do echo $((1 + RANDOM % 6)); done | sort |
uniq -c
     12 1
     17 2
     22 3
     19 4
     16 5
     15 6


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

Next time, the output of 'for i in $(seq 0 100); do echo $((1 + RANDOM
% 6)); done | sort | uniq -c' will be different.

When redirecting the output of the command into files, these are also
different.

Since all of this was so strange, I reproduced it on Fedora 36 in a
container (using zsh -f) as well as on my Fedora 37 host. Also in a VM,
with a fresh Fedora 37 install on Hetzner and a Debian 10 install, to
make sure, it's not due to a distro specific modification.

I also validated, that this behaviour doesn't exist in bash.

I hope you'll have fun debugging it, I have no idea where to even
start.

Greetings
Sheogorath


             reply	other threads:[~2023-02-25 23:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-25 23:02 Sheogorath [this message]
2023-02-25 23:21 ` Lawrence Velázquez

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=010701868ad0a7e8-be8c1ddd-a63c-4002-926a-b7ba25a0cebb-000000@eu-central-1.amazonses.com \
    --to=zsh@sheogorath.shivering-isles.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).