Allow partial list of ids for sortByIds

Refactored sortByIds to be more robust and predictable in the case of an incomplete list of ids to use for sorting. Any unlisted ids will be appended to the end in their original order.
Well, you can replace `(1)` and `(2)` with `(continuous range)` and `(random distribution)`. But then the fact that the random distribution works implies that a continuous range works too, right? Thus the second test is IMO sufficient.