shuf: Use the newly introduced AK::shuffle function
This commit is contained in:
parent
352048ce0e
commit
a559e26f68
Notes:
sideshowbarker
2024-07-17 18:13:59 +09:00
Author: https://github.com/kuzux Commit: https://github.com/SerenityOS/serenity/commit/a559e26f68 Pull-request: https://github.com/SerenityOS/serenity/pull/16386 Reviewed-by: https://github.com/AtkinsSJ
1 changed files with 1 additions and 11 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue