ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
sort by random hash of key... I don't even know what's
that supposed to mean ? I never thought of a hash as
possibly being random, I thought they were
deterministic.
ychaouche#ychaouche-PC 15:57:56 ~/DOWNLOADS/APPS/THUNDERBIRD/thunderbird $ sort --version
sort (GNU coreutils) 8.21
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Mike Haertel and Paul Eggert.
ychaouche#ychaouche-PC 15:58:57 ~/DOWNLOADS/APPS/THUNDERBIRD/thunderbird $ sort --help | grep '\-R'
-R, --random-sort sort by random hash of keys
numeric -n, random -R, version -V
ychaouche#ychaouche-PC 16:00:15 ~/DOWNLOADS/APPS/THUNDERBIRD/thunderbird $ man --pager=cat sort | grep '\-R' -A1
-R, --random-sort
sort by random hash of keys
--
sort according to WORD: general-numeric -g, human-numeric -h, month -M, numeric -n, random -R, version -V
ychaouche#ychaouche-PC 16:00:40 ~/DOWNLOADS/APPS/THUNDERBIRD/thunderbird $
Sadly, the definitive documentation for GNU tools are not man pages, but info manuals. For sort -R, it says:
Quote:
-R --random-sort --sort=random
Sort by hashing the input keys and then sorting the hash values. Choose the hash function at random, ensuring that it is free of collisions so that differing keys have differing hash values. This is like a random permutation of the inputs (see shuf invocation), except that keys with the same value sort together.
If multiple random sort fields are specified, the same random hash function is used for all fields. To use different random hash functions for different fields, you can invoke sort more than once.
The choice of hash function is affected by the --random-source option.
That is more or less identical, but you are right, this info manual is better - although sort by those hashes means really grouping by identical keys.
And also means this is reproducible, so the sort will give always the same "random" result with the same hashing algorithm (see --random-source=FILE).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.