I want a file of randomly generated positive or negative serial integers. For now, I ask the file contain roughly (no guarantee required) equal numbers of negative and positive, but make it easy to change the proportions later. By ‘serial’, I mean the kth random negative is equal to -k, and the kth random positive is equal to +k.
This GNU Bash script one-liner would satisfy the file format, but just wouldn’t be random.
$ seq -1 -1 -5 && seq 1 5 -1 -2 -3 -4 -5 1 2 3 4 5
This example shows what I’m looking for even better, but is still not random since the integers alternate predictably between negative and positive.
$ paste <(seq -1 -1 -5) <(seq 1 5) | tr '\t' '\n' -1 1 -2 2 -3 3 -4 4 -5 5
Sending one of these through the shuf command makes them randomly negative or positive, but they lose their serial-ness.
$ paste <(seq -1 -1 -5) <(seq 1 5) | tr '\t' '\n' | shuf -5 4 3 2 -2 1 -1 -4 5 -3
Note: I’m trying to test algorithms that sort lists/arrays of bits (zeros and ones), but if I use 0s and 1s I won’t be able to analyse the sort’s behaviour or tell if stability was preserved.
Let’s start golf contest? (44)
Edit: daotoad’s 40 chars version