Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Bug report: Strange behaviour with random, sort and uniq



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




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