Unsort

Up ../

Output a Random Permutation of Input Lines

Outputs a random permutation of the lines read from file or if omitted from stdin. Unfortunately the distribution of the lines are not uniform.

The motivation for this code was to push the storage of intermediate result out to temporary file to relieve the load on memory. The filesystem will store at most 150% of the input while the memory use should be largely independent of input size.

SYNOPSIS

unsort [file]

EXAMPLES

Typical use would be where a sequence of values is easy to generate but a permutation is need for the input of another process.

seq 1 1024 | unsort | program_needing_nums_in_random_order

Generate all the internet addresses between 10.1.0.0 and 10.1.255.255, permuting them and feeding them to a subnet merging program for testing.

( for i in `seq 0 255`
        do
                for j in `seq 0 255`
                do
                        printf "10.1.%d.%d\n" $i $j
                done
        done
        ) | unsort | subnet_merge

# Should be 10.1.0.0/16

SOURCE

Sources at https://github.com/pellucida/unsort/ Sources in files

Uses random(3) and clock_gettime(2) if available otherwise time(2) and getpid(2) to seed the pseudo- random number generator. Alternatively /dev/random could be used. Otherwise doesn't use any unusual features.

SEE ALSO

shuf(1) and sort(1) [gnu core-utils] especially the usage sort --random-sort.

LICENSE

Creative Commons CC0 http://creativecommons.org/publicdomain/zero/1.0/legalcode

AUTHOR

James Sainsbury