Can you sort by random?

Solution 1:

In my head

sorting

Is really just ordering. There's no inherent requirement that the ordering in particular be well-defined, ascending/descending, or aesthetically pleasing.

M-W definition 3

the act of separating things and putting them in a particular order : the act of sorting things

A random order doesn't seem to break these definitions.


Let me expand my answer taking in the comments below and getting vaguely rigorous. No need to continue if you've been convinced.

A collection may be stated as

Collection = { x1, x2, ... , xn }

An order is a function that goes from N -> N where N is a natural number 1..n.

For a collection to be ordered that just means I can generate a list

(x1, 1)

(x2, 2)

(x3, 3)

Where the left hand side is the item and the right hand side is the position.

An order function just transforms positions. A random ordering might be

f:

1 -> 3

2 -> 1

3 -> 2

I would apply that order function to get a new ordering out. I have successfully separated things and put them in a particular order. The new collection is still ordered, it's just been sorted into a different one.


Vaguely philosophical addendum

The idea of sorting has to be this vague because you aren't limited to sorting items lexicographically or numerically. Let's say I want to sort a set of countries. The countries themselves cannot be ordered meaningfully but I can define an ordering based on items that I know how to order. I can do it by population, or by area, or any number of other metrics. I also might be able to do it by ratio of people to cattle or any number of arbitrary functions. Because the potential orderings are so arbitrary all we can really say about them is that they are orderings. You'll have a bugger of a time trying to define rules for ordering that capture all potential valid cases. After all, it's perfectly valid for me to say that I'm going to sort this list of countries based on how happy they make me. These countries are now being judged on something that's outside the system where the system is the list. In a similar way, your random ordering is being sorted by something that's outside the system where the system is the list. In the case of the random sort, it's likely truly being ordered on a function of the system time.

Solution 2:

What the entry in the manual says is:

-R, --random-sort sort by random hash of keys

Ie, the software hashes each entry using a hashing function primed with a "random" state and then, using a normal deterministic sorting algorithm, sorts the entries based on their hashes. (Random is a property of the hash.)

This is arguably an overly implementation-oriented description of this option (it may be a better idea to describe the end result instead of the implementation in the user documentation) but the quote from the documentation is not an oxymoron.


Then we have your question, whether sort by random is an oxymoron, even though this ends up not actually being applicable to the quoted text.

This use (or variations thereof, I think sort randomly would sound better), is something that does occur to some extent. However, my impression is that this can be attributed to computer jargon primarily, where sort doesn't necessarily have the same implication as it does normally.

Looking at dictionary definitions of sort will essentially tell you that it's arranging items based on some quality. Considering that the definition does have an implication of bringing order, this use does seem to contradict that.

I think that order randomly would be a more generally accepted alternative. (Dictionaries include a meaning of simply arranging items in a certain order, for one thing.)

Solution 3:

"Random" does not apply to "sort" in this example, but to "hash of keys".

You shouldn't read it as "sort by random, hash of keys", but as "sort by the keys, which themselves are random", so you are not "sorting by random", but sorting by the keys / hashes, which might happen to be random, but the sorting is done with regard to these keys (or hashes), and is not random by itself.

Solution 4:

Technically speaking, no. It is an oxymoron. Shuffle is more fitting than random.