shuf: Use the newly introduced AK::shuffle function

This commit is contained in:
Arda Cinar 2022-12-09 16:53:33 +03:00 committed by Sam Atkins
parent 352048ce0e
commit a559e26f68
Notes: sideshowbarker 2024-07-17 18:13:59 +09:00

View file

@ -54,17 +54,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (lines.is_empty())
return 0;
// Fisher-Yates shuffle
Bytes tmp;
for (size_t i = lines.size() - 1; i >= 1; --i) {
size_t j = get_random_uniform(i + 1);
// Swap i and j
if (i == j)
continue;
tmp = lines[j];
lines[j] = lines[i];
lines[i] = tmp;
}
AK::shuffle(lines);
Array<u8, 1> output_delimiter = { '\n' };
for (size_t i = 0; i < min(head_count.value_or(lines.size()), lines.size()); ++i) {