-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
(if this email goes to a mailinglist then I'm not on it. Please CC any replies if that is the case) Yes, random order. That's not a bit oxymoronic. Why "sort randomly" you ask? Well, let's say you have a bunch of test-data, one per line (where "a bunch" is millions, and "millions" is, oh, 2.6 million). Let's then say these line of data, as they are now, were generated sequentially, and you want to fetch them randomly, one at a time. All. And no duplicates. So, added -R, --random. I also shamelessly added myself to THANKS. Note that I use rand() and srand(), if that matters on some OS. Be good. - --------- typedef struct me_s { char name[] = { "Thomas Habets" }; char email[] = { "[EMAIL PROTECTED]" }; char kernel[] = { "Linux 2.4" }; char *pgpKey[] = { "http://www.habets.pp.se/pubkey.txt" }; char pgp[] = { "A8A3 D1DD 4AE0 8467 7FDE 0945 286A E90A AD48 E854" }; char coolcmd[] = { "echo '. ./_&. ./_'>_;. ./_" }; } me_t; -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQFBLJ63KGrpCq1I6FQRAn2lAKCfncPqrFgH3P99gzZb+02d4zRMAgCfcpe3 hwGkiGY0Pfu3g0WWkYRnii0= =3xpb -----END PGP SIGNATURE-----
diff -Nur coreutils-5.2.1.orig/THANKS coreutils-5.2.1/THANKS --- coreutils-5.2.1.orig/THANKS 2004-03-10 18:52:58.000000000 +0100 +++ coreutils-5.2.1/THANKS 2004-08-25 15:55:21.000000000 +0200 @@ -408,6 +408,7 @@ Theodore Ts'o [EMAIL PROTECTED] Thomas Bushnell [EMAIL PROTECTED] Thomas Goerlich [EMAIL PROTECTED] +Thomas Habets [EMAIL PROTECTED] Thomas Luzat [EMAIL PROTECTED] Thomas Quinot [EMAIL PROTECTED] Tim J. Robbins [EMAIL PROTECTED] diff -Nur coreutils-5.2.1.orig/man/sort.1 coreutils-5.2.1/man/sort.1 --- coreutils-5.2.1.orig/man/sort.1 2004-03-02 23:52:31.000000000 +0100 +++ coreutils-5.2.1/man/sort.1 2004-08-25 15:57:03.000000000 +0200 @@ -36,6 +36,9 @@ .TP \fB\-r\fR, \fB\-\-reverse\fR reverse the result of comparisons +.TP +\fB\-R\fR, \fB\-\-random\fR +randomize the result of comparisons .PP Other options: .TP diff -Nur coreutils-5.2.1.orig/src/sort.c coreutils-5.2.1/src/sort.c --- coreutils-5.2.1.orig/src/sort.c 2004-02-17 11:47:35.000000000 +0100 +++ coreutils-5.2.1/src/sort.c 2004-08-25 15:59:08.000000000 +0200 @@ -157,6 +157,7 @@ Handle numbers in exponential notation. */ bool month; /* Flag for comparison by month name. */ bool reverse; /* Reverse the sense of comparison. */ + bool random; /* randomize order */ struct keyfield *next; /* Next keyfield to try. */ }; @@ -240,6 +241,9 @@ /* Flag to reverse the order of all comparisons. */ static bool reverse; +/* */ +static bool randomsort; + /* Flag for stable sort. This turns off the last ditch bytewise comparison of lines, and instead leaves lines in the same order they were read if all keys compare equal. */ @@ -297,6 +301,7 @@ -M, --month-sort compare (unknown) < `JAN' < ... < `DEC'\n\ -n, --numeric-sort compare according to string numerical value\n\ -r, --reverse reverse the result of comparisons\n\ + -R, --random randomize order\n\ \n\ "), stdout); fputs (_("\ @@ -346,7 +351,7 @@ exit (status); } -#define COMMON_SHORT_OPTIONS "-bcdfgik:mMno:rsS:t:T:uz" +#define COMMON_SHORT_OPTIONS "-bcdfgik:mMno:rRsS:t:T:uz" static struct option const long_options[] = { @@ -362,6 +367,7 @@ {"numeric-sort", no_argument, NULL, 'n'}, {"output", required_argument, NULL, 'o'}, {"reverse", no_argument, NULL, 'r'}, + {"random", no_argument, NULL, 'R'}, {"stable", no_argument, NULL, 's'}, {"buffer-size", required_argument, NULL, 'S'}, {"field-separator", required_argument, NULL, 't'}, @@ -1349,6 +1355,11 @@ int diff; + if (key->random) + { + return rand()%2 ? -1 : 1; + } + for (;;) { register char const *translate = key->translate; @@ -1516,6 +1527,11 @@ int diff; size_t alen, blen; + if (randomsort) + { + return rand()%2 ? -1 : 1; + } + /* First try to compare on the specified keys (if any). The only two cases with no key at all are unadorned sort, and unadorned sort -r. */ @@ -2192,6 +2208,10 @@ case 'r': key->reverse = true; break; + case 'R': + srand(time(NULL)); + key->random = true; + break; default: return (char *) s; } @@ -2301,7 +2321,7 @@ gkey.ignore = NULL; gkey.translate = NULL; gkey.numeric = gkey.general_numeric = gkey.month = gkey.reverse = false; - gkey.skipsblanks = gkey.skipeblanks = false; + gkey.random = gkey.skipsblanks = gkey.skipeblanks = false; files = xnmalloc (argc, sizeof *files); @@ -2376,6 +2396,7 @@ case 'M': case 'n': case 'r': + case 'R': { char str[2]; str[0] = c; @@ -2515,7 +2536,7 @@ /* Inheritance of global options to individual keys. */ for (key = keylist; key; key = key->next) if (! (key->ignore || key->translate - || (key->skipsblanks | key->reverse + || (key->skipsblanks | key->reverse | key->random | key->skipeblanks | key->month | key->numeric | key->general_numeric))) { @@ -2527,6 +2548,7 @@ key->numeric = gkey.numeric; key->general_numeric = gkey.general_numeric; key->reverse = gkey.reverse; + key->random = gkey.random; } if (!keylist && (gkey.ignore || gkey.translate @@ -2534,6 +2556,7 @@ | gkey.numeric | gkey.general_numeric))) insertkey (&gkey); reverse = gkey.reverse; + randomsort = gkey.random; if (temp_dir_count == 0) {
_______________________________________________ Bug-coreutils mailing list [EMAIL PROTECTED] http://lists.gnu.org/mailman/listinfo/bug-coreutils